I have written a struct in iOS playground and want to customize the print format of it.
struct Point {
let x: Int, y: Int
}
extension Point: CustomStringConvertible {
var description: String {
switch (x, y) {
case let (x, 1..<10):
print("y in the range")
return "(\(x), 1..<10)"
default:
return "(\(x), \(y))"
}
}
}
let p = Point(x: 1, y: 1)
print(p)
The result is
I cannot understand that even though I called print
only once but y in the range
message is being printed 4 times.