TSPL: Revised discussion of optionals in "The Basics"

Following our normal process, this would have gone through a pitch here early in the writing process. However, I started working on these changes before the book was an open source project. (Discussions as far back as 2017, with the first commit in 2019.)

Instead, I'll call out the PR here, in case folks want to provide feedback. The changes are as follows:

  • Reframe the discussion of optional unwrapping to not conceptually rely on force unwrapping.
  • Highlight the value of non-optional types never being nil, and how you can't forget to handle nil on an optional.
  • Explicitly list the ways you can handle a nil value, and briefly introduce the ?? operator.
  • Explain when you should consider using force unwrapping.
  • Reduce the comparison to C and Objective-C.
  • Fix some mis-use of note boxes, where they were highlighting information instead of asides that readers can choose to skip.

https://github.com/apple/swift-book/pull/143

5 Likes