let a: [(Int, Int)] = [(1, 2), (3, 4)] a.contains((3, 4)) // no! // error: cannot convert value of type '(Int, Int)' // to expected argument type '@noescape ((Int, Int)) throws -> Bool'
let a: [(Int, Int)] = [(1, 2), (3, 4)] a.contains({ $0 == (3, 4) }) // yes!
Tuples can’t conform to protocols, so they don’t count as Equatable.
2 Comments
[…] Erica Sadun notes that Swift will let you create an array of tuples: […]
Thanks for the Highlights for Children memories (from the 1960’s for me). I appreciate the fine blogging and reporting too.