Swift Extensions
An extension adds methods, computed properties and protocol conformance to an existing type, even built in ones.
Example
extension Int {
var isEven: Bool { self % 2 == 0 }
func squared() -> Int { self * self }
}
print(4.isEven, 5.squared())Exercise
Add to an existing type.
String { }Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.