Learning Swift · Part 8 of 8
Day Eight
Done
The Goal
Today is day 8 of learning Swift. I’ve started book four of the documentation “Advanced patterns” here we cover subscripts, inheritance, initialization and deinitialization, optional chaining, error handling and concurrecny. Along with this continue with the L9 of the Stanford youtube video.
Notes:
- Try use
aspectRatioto best handle dynamic screens - Text can show numbers directly by passing them in like:
Text(0.4, format: .number/.percent) - To unwrap a variable in an if statement we can do
if let endTime {
}
That is the same as doing
if let endTime = endTime {
}
- We can build timers using the
TimeDataSourcewhich will keep counting. An example of this is below. This increase the count from the current date
Text(TimeDataSource<Date>.currentDate, format: .offset(to: startTime, allowedFields: [.minute, .second]))
- You can use
.flexibleSystemFont()to build fonts that can scale. someis greatly preferred thanany
Important protocols
Equatable- makes == work;Hashable- For when someone wants to be able to look your stuff upIdentifiable- used by SwiftUI to match your model up with specific views