Swift
Associated types and values
Enums and associated values.
Protocols and associated types.
Generics, etc.
Why generics?
Specializing a generic.
Constraining an extension based on the type of a generic.
Improving readability of specialized generics with opaque types.
Type erasure
Swift is a type-safe language
Collections
Apple’s concrete implementations:
Set, Dictionary, Array (when order matters, although can always sort by)
Generic
All value types (but elements need not be)
Abstracting the above; Apple’s protocols and concepts:
Collection, Hashable and hasher. (For example, Array as a Collection.)
Sequence, for-in loops, iterators. (For example, makeIterator and encapsulation.)
Two collections A and B:
Adding: A + B
Prepending: B + A
Subtracting: A - B
Splitting: C -> (A, B)
Closures, functions, and the call stack
Trailing closures
As arguments (IoC?)
Examples: UIView.animateWithDuration, sortBy, map, filter, reduce, forEach
Can also pass in a function instead of a closure. (Wait, are functions a special kind of closure in Swift or are closures a special kind of function?)
Writing user-friendly APIs: call site, labels, @discardableResult
Memory management: the call stack and recursion
Value types
Structs are not classes: differences, advantages (e.g. threadsafety), disadvantages (e.g. sharing data)
Value semantics and copy-on-write (that is, value types are not always passed by value in Swift)
What if I really need a reference?
When do I need a reference? (e.g. SwiftUI)
The heap (not the call stack)
Objects, aka class instances
Automatic Reference Counting (ARC)
Comparison with other memory-management models
Control flow
if-then
p && q is not the same as q && p (and why this matters in partice)
switch
Interop with legacy code and other non-Swift modules
Bridging headers
Djini
Best practices for avoiding “spaghetti code”
Nullability
For a complete guide to Swift, see swift.org. If you are new to Swift, you might want to start with swift.org’s Guide Tour.