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
    }
}

   

Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.