Reputation: 131
Been going bonkers with this one as all samples I find use the NSRange version but in Swift 2 this method returns a Range so no location to test.
I know that the result of a not found is {NotFound,0} but don't have a scooby doo how to test for it?
if (contact.facebook!.rangeOfCharacterFromSet(characterSet.invertedSet).location != NSNotFound){...}
errors but I cant find out how to query Range
Upvotes: 3
Views: 1990
Reputation: 91
Cast it to a NSString
let objcString = string as NSString
let characterSet = NSCharacterSet.decimalDigitCharacterSet().invertedSet
if objcString.rangeOfCharacterFromSet(characterSet).location != NSNotFound {
return false
}
Upvotes: 9