Consider the following Swift code.
var a = [(1, 1)]
if contains(a, (1, 2)) {
println(\"Yes\")
}
All I need is to check if a
Maybe too old for this question hope someone will get help with more option.
You may use switch instead of if condition
var somePoint = [(0, 1), (1, 0), (0, 0), (-2, 2)]
for innerSomePoint in somePoint {
switch innerSomePoint {
case (0, 0):
print("\(innerSomePoint) first and second static")
case (_, 0):
print("\(innerSomePoint) first dynamic second static")
case (0, _):
print("\(innerSomePoint) first static second dynamic")
case (-2...2, -2...2):
print("\(innerSomePoint) both in between values")
default:
print("\(innerSomePoint) Nothing found")
}
}
Also have some more option to do check here from apple doc
somePoint = [(1, 1), (1, -1), (0, 0), (-2, 2)]
for innerSomePoint in somePoint {
switch innerSomePoint {
case let (x, y) where x == y:
print("(\(x), \(y)) is on the line x == y")
case let (x, y) where x == -y:
print("(\(x), \(y)) is on the line x == -y")
case let (x, y):
print("(\(x), \(y)) is just some arbitrary point")
}
}