Protocols are quite new to me but immediately made sense. After taking a few days off from the course, my brain felt strangely fresh and responsive to new information. Like some of the other recent topics, I’m looking forward to seeing how these work out in practice, but there were some simple but interesting examples provided on the spot that caught my attention.
extension Int {
func isEven() -> Bool {
return self % 2 == 0
}
}
Perhaps this isn’t good to admit, but I didn’t realise that you could extend core types like integers and integers by adding functions or new properties.
extension String {
var isLong : Bool {
return count > 25
}
}
References
- Day 11 – https://www.hackingwithswift.com/100/swiftui/11
- Protocols and extensions summary – https://www.hackingwithswift.com/sixty/9/6/protocols-and-extensions-summary