Reputation: 12559
Is is not possible to create a range and call its contains method like this:
1...12.contains(1)
When I create a var range = 1...12
and print its dynamicType I get a Swift.Range<Swift.Int>
, so I'm guessing is not a type mismatch problem, or is it?
Upvotes: 0
Views: 81
Reputation: 13243
Another nice way to check this: (with the pattern match operator)
if 2...5 ~= 4 {
// do something
}
Upvotes: 2
Reputation: 694
place the range in parenthesis and it should work:
(1...12).contains(1)
Upvotes: 0
Reputation: 9039
In this case the problem was that of operator precedence:
(1...12).contains(1) // -> true
(the code does look ambiguous otherwise)
Upvotes: 3