iOS ● ● ○ Swift 6

Kodebits Day 94: Operator Overloading

Sep 17 2026
Practice operators with a short swift challenge.

What does this print?

struct Point {
  var x: Int, y: Int
  static func + (
    a: Point, b: Point
  ) -> Point {
    Point(
      x: a.x + b.x,
      y: a.y + b.y
    )
  }
}
let p = Point(x: 2, y: 3)
  + Point(x: 4, y: 5)
print("\(p.x),\(p.y)")


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

6,8

Explanation:

Operator overloading customizes how operators work with custom types.

[/spoiler]


Further Reading