Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rangeOfCharacterFromSet(characterSet).location not Swift?

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

like image 261
Piginhat Avatar asked May 26 '26 11:05

Piginhat


1 Answers

Cast it to a NSString

let objcString = string as NSString

let characterSet = NSCharacterSet.decimalDigitCharacterSet().invertedSet            

if objcString.rangeOfCharacterFromSet(characterSet).location != NSNotFound {
     return false
}
like image 175
XXrebel_coderXX Avatar answered May 30 '26 08:05

XXrebel_coderXX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!