Day 12 (part 4 of 4) of 100 Days of Swift

Days 1 to 12 of the “100 Days of Swift” course make up the “Introduction to Swift” section.

Day 12‘s lesson covered optionals, unwrapping, and typecasting. Day 12 is divided into 10 sections with a section 11 being the lesson summary.

Thoughts about Day 12

Today’s Day 12 final study session covered: a revisit of optional chaining followed by new sections about optional try, failable initializers, and typecasting.

I feel that I need to watch all the Day 12 lesson videos again but this time back-to-back in one sitting in order to help stick into my brain the concepts of optionals, unwrapping, and typecasting.

The background music for today’s study session was streamed from YouTube and titled “EXTREME PROGRAMMING FOCUS MUSIC – Beta Binaural Beats – 60 Minutes of the Best Brainwave Music“, which was set to loop because the music lasts only 56 minutes 25 seconds.

My Day 12 (part 4 of 4) notes taken from my paper notebook

  • 7. Optional chaining (revisited)
    • if the optional chaining symbol (question mark) ? is added to a chained property then if the optional chained property returns nil then the rest of the chained properties are ignored and Swift will return nil immediately.
  • 8. Optional try
    • try? is an alternative to using do, try, and catch in Swift.
    • try? tries to convert a throwing function call into an optional
      • if the function succeeds then its return value will be an optional containing what you would normally have received.
      • if it fails then the return value is an optional that was set to nil.
  • 9. Failable initializers
    • failable initializers are used when an intializer for a struct or class can fail.
    • rather than return a new object instance, failable initializers return an optional instance of nil if the initialization failed.
  • 10. Typecasting
    • typecasting tells Swift that an object it thinks is Type A is actually a Type B.
  • 11. Optionals summary
    • no notes recorded

Today’s total study time: 2 hours

100 Days of Swift cumulative study time: 37 hours 15 minutes

[Note: those are actual study time values after subtracting break-time minutes from the Day’s study session]