switch on other types
Swift ⟩ Pattern Matching ⟩ Sentence Patterns ⟩
// CGPoint
let point = CGPoint(x: 7, y: 0)
// switch on Tuple
switch (point.x, point.y) {
case (0, 0): print("On the origin!")
case (0, _): print("x=0: on Y-axis!")
case (_, 0): print("y=0: on X-axis!")
case let (x, y) where x == y:
print("On y = x")
default:
print("Quite a random point here.")
}
Last updated
Was this helpful?