Protocols
A protocol is a contract: a list of properties and methods that a type promises to provide. You have already seen View (it must have a body).
Extensions
Extensions add new features to existing types, even to Apple's own types, without changing their source code.
Default Implementations
Protocols You Will Use Every Day
| Protocol | Meaning | Used for |
|---|---|---|
Identifiable | Has a stable id | List and ForEach rows |
Equatable | Can be compared with == | Comparing values, onChange |
Hashable | Can be used in sets and as dictionary keys | NavigationStack paths, selections |
Codable | Can be converted to and from JSON | Networking and saving |
Comparable | Can be sorted with < | Sorting custom types |
CaseIterable | Lists all enum cases | Pickers |
Generics
Generics allow one function or type to work with many types. Array<Int> and Array<String> are the same generic type with different parameters.
some View and any
some View means: a specific view type that Swift figures out for me. any Drivable means: any value of a type that conforms to the protocol. Use some for return values like body, and any for mixed collections.
Conclusion
Protocols, extensions and generics make Swift code flexible and reusable. Learn the common protocols, because SwiftUI and Codable rely on them everywhere.

