iOS ● ○ ○ Swift 6

Kodebits Day 63: Extension Method

Jul 24 2026
Practice extensions with a short swift challenge.

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]


Further Reading