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]