Unit 02 of 03
The Type System
Optionals as the expression of absence in the type, and safe unwrapping; value and reference semantics with structures and classes; enumerations; stored, computed and observed properties; protocols, extensions, generics, error handling and access control.
Published Updated
Lessons
- 01 Optionals Measuring how absence is expressed in the type, why a transforming closure never runs on nil, and where absence stops in nested layers. 13 min read
- 02 Unwrapping Optionals Measuring when the right-hand side of if let and guard let, a ?? chain and optional chaining are evaluated. 14 min read
- 03 Structures and Classes Measuring copying on assignment for structures, sharing for classes, when a default value is built, and why a copy appears at the first mutation. 13 min read
- 04 Enumerations Measuring when a raw value and an associated value are set up, how pattern matching opens them, and why a computed property runs on every read. 13 min read
- 05 Properties Measuring when stored, computed and observed properties, lazy properties and static let values are set up. 12 min read
- 06 Protocols Measures when a value that fulfills a protocol requirement is evaluated: a default implementation runs on every call, but the conforming type decides the moment. 13 min read
- 07 Extensions Measures adding methods, computed properties and protocol conformance to an existing type from the outside; shows that a stored property cannot be added, and the type-level exception. 13 min read
- 08 Generics Applies one body to many types with type parameters and constraints; measures the transformer of a lazy sequence on every access and that of an eager map immediately. 13 min read
- 09 Error Handling Measures that nothing after the `throw` line in the body of a throwing function ever runs, while a `defer` block runs on every exit. 14 min read
- 10 Access Control Measures that making a cache `private` does not change the moment of evaluation, and that access control is decided at compile time. 14 min read