What does this print?
extension Int {
func squared() -> Int {
return self * self
}
}
let num = 7
print(num.squared())
print(3.squared())
Try it in the online Swift Playground →
[spoiler title="Solution"]
Answer:
49 9
Explanation:
Extensions add methods to existing types without subclassing.
[/spoiler]