Self Requirements and Equatable Design
Protocols that use Self and how Equatable/Comparable leverage them.
Welcome
`Self` in a protocol refers to the concrete type that conforms. It enables protocols like `Equatable` and `Comparable` to work with heterogeneous types safely.
Self as Parameter Type
```swift
protocol Equatable {
static func == (lhs: Self, rhs: Self) -> Bool
}
```
`Self` means both parameters must be the *same* concrete type. You can't compare an `Int` with a `String` through this protocol.
All lessons in this course
- Protocol Composition with &
- Conditional Conformance
- Self Requirements and Equatable Design
- Protocol-Oriented Design Principles