0Pricing
Swift Academy · Lesson

Protocol Composition with &

Combining multiple protocols into a single type requirement.

Welcome

Protocol composition lets you combine multiple protocols into a single type requirement using `&`. This is Swift's answer to multiple inheritance.

Basic Composition

```swift protocol Named { var name: String { get } } protocol Aged { var age: Int { get } } func describe(_ entity: Named & Aged) { print("\(entity.name) is \(entity.age)") } ``` `Named & Aged` is a temporary type requirement, not a new 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