WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Progress - Green-Orion: Just finished Day 43 & question on Previews

Forums > 100 Days of SwiftUI

Just wanted to share! Posted this initially to share I'd finished Day 41, and edited based on feedback.

   

Excellent!

There are a number of folks here willing to help explain concepts or help you when you're stuck!

Please Read

Please read this thread and the response from @twoStraws. See-> How to Post Progress

In short, please keep posting your progress. However, instead of a new post for each day, you can edit this post!

Instead of the title "Just Finished Day 41", consider changing your post title to: Green-Onion's Progress: Day 41 Complete! Next week it will read: Green-Onion's Progress: Day 47 Complete! Keep changing the title as you progress.

Add to the post! After each milestone, post a snip of your progress, your quiz scores, and the concepts you found fun, or difficult. There are other articles, blog posts, or YouTube videos we can point you to, to help you solidify a concept, or to push your boundaries.

Keep coding!

1      

For inspiration, here is Vince's journey starting at Day 69. This is a great model to follow.

See-> Vince's 100 Day Journey

   

Thanks for the feedback. Now up to Day 43. I needed some help to finish Day 42 Challenges - my main issue was to get the Previews working for the layout Views - I have a hard time figuring out what needs to be included to make the Previews work. I've gone through the course material several times but it still is a bit of a guessing game to me. If there is another guide on how to make Previews work for views that take in information from parent or sibling views, would anybody be able to share that with me? Many thanks.

   

Sander trips on a common problem!

I have a hard time figuring out what needs to be included to make the Previews work.

Not sure what challenge you have with previews, but here are two writeups from other posts.

See-> Preview Scaffolding

And here's another post describing setting up variables to work with previews. See-> More on Previews

KEEP CODING!

1      

Paul recommend that you make a static property of example in your data struct eg

struct User: Identifiable {
    var id = UUID()
    var firstName: String
    var lastName: String

    static let example = [
        User(firstName: "Paul", lastName: "Hudson"),
        User(firstName: "Nigel", lastName: "Gee")
    ]
}

then when you want to use it you can simple do

struct ContentView: View {
    let users: [User]
    var body: some View {
        List(users) { user in
            Text("\(user.firstName) \(user.lastName)")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView(users: User.example) // <- Using static example
    }
}

   

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.