Day 11 of 100 days of swift ui
Oluwasanmi Aderibigbe
Posted on March 25, 2021
I just finished day 11 of hacking with swift ui. Today I learnt about Protocols and extension methods in Swift.
Protocols in Swift are a way of defining properties and methods a class or struct should have. The are created with the keyword protocol
Extension methods are a pretty cool feature in Swift that allows us to add methods to existing structs or class without modifying the struct or class
extension Int {
func squared() -> Int {
return self * self
}
}
let number = 8
number.squared()
The code above creates an extension method that squares an Int
💖 💪 🙅 🚩
Oluwasanmi Aderibigbe
Posted on March 25, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.