Build a lessons app
Fetch lessons, model states and render a SwiftUI list.
What you will be able to do
- Decode into Identifiable models.
- Model loading, error and content states.
- Use List with stable ids.
- Keep the network layer separate from the view.
In plain English
The capstone connects the language features to a UI. Fetch JSON, decode it into Identifiable models, keep loading and error states, and render a List with stable ids. Keep the service separate from the view so both are testable.
struct LessonsView: View {
@State private var lessons: [Lesson] = []
var body: some View {
List(lessons) { lesson in
VStack(alignment: .leading) {
Text(lesson.title).font(.headline)
Text("(lesson.minutes) minutes").font(.caption)
}
}
.task {
lessons = (try? await LessonService().load()) ?? []
}
}
}Your turn
EasyRender a list
Render lessons in a List using their Identifiable conformance.
SWIFT · starter
List()Check your understanding before moving on.
Knowledge checkQuestion 1
Which SwiftUI modifier runs async work tied to the view lifecycle?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.