100 Days of SwiftUI
2026-05-29
Project 8, part 2
- Focus on getting the data right
- Meeting generics
- getting more comfortable with splitting code out of the main
ContentView - colors!
Loading a specific kind of Codable data
- bringing JSON data in; need to consider how to do it in a way that is easy to maintain and doesn’t “clutter our code”
- moved
Decodecode out ofContentViewinto another file- makes
ContentVieweasier to read - gives the possibility to easily reuse the code in another project
- aided by adding more reasons to throw
FatalError
- aided by adding more reasons to throw
- makes
Using generics to load any kind of Codable data
- you can nest structs to give added context (so instead of talking about
Crew, you talk aboutMission.Crew) - generics allow code to work with a variety of different types (such as a dictionary of astronauts and an array of missions)
- uses a placeholder, conventionally
Tin angle brackets (aka “Pulp Fiction brackets”?!) after thefuncname, e.g.func decode<T>... - note that
Tstands for the type of thing, so if it’s already an array, you don’t need to use[T] - when you actually go to use the function you have to tell it what it is going to return

We call them “chicken beaks”Or maybe it should be 
Formatting our mission view
- the images we’re using are named
apollo1, apollo7...but theidin theMissionstruct (and the JSON) is just an integer. - adding a “Display name” property to the
Missionstruct makes it possible to have only one place where you need to develop the name for views. - same for formatted dates (so they read correctly in different locales)
- you can specify app colors with Assets or with an extension. One is better for visual, other is better for version control
Colorconforms toShapeStyle, so extend that- I did it for the text color also
- you can set a preferred display mode (
.preferredColorScheme(.light)or.dark) so you don’t have to design the colors twice ;)