0Pricing
Swift Academy · Lesson

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

  1. Protocol Composition with &
  2. Conditional Conformance
  3. Self Requirements and Equatable Design
  4. Protocol-Oriented Design Principles
← Back to Swift Academy