Thread 1, Day 12 - Tuesday, November 8, 2022
Agenda
- SwiftUI: Composition of Views Using Custom Structures
- Remember D.R.Y. ?
- Don't repeat yourself.
- We can write our own structures that conform to the
View
protocol.- These custom structures build upon the structures like
VStack
,HStack
,ScrollView
, et cetera that are provided by Apple through the SwiftUI framework. - By using custom structures, we avoid having to make repetitive changes to our code.
- As well, the overall number of lines of code that it takes to write an app is much lower.
- These custom structures build upon the structures like
- Remember D.R.Y. ?
- Exercise: Improving the List View in FavouriteThings
- Currently, the list view looks like this:
NavigationLink
labels can show any view, not just aText
view.- Using your new knowledge from yesterday's class about how to combine
VStack
andHStack
structures, and from today's class about how to create a new custom structure, modify your project so that the list view looks like this instead:
HintTo re-use existing images in your app and show a smaller square thumbnail, the view modifiers shown here will do the trick:
- Currently, the list view looks like this:
To-do items
Before our next class...