I am currently converting my codes to swift 3 and i encounter the above mentioned error with the following codes.
func containsAlphabets() -> Bool {
//Checks if all the characters inside the string are alphabets
let set = NSCharacterSet.letters
return self.utf16.contains( { return set.characterIsMember($0) } )
}
Any kind souls can assist on this?
In Swift 3, CharacterSet
is re-designed to work well with UnicodeScalar
rather than UTF-8 code point.
In this case, you can write something like this:
var containsAlphabets: Bool {
//Checks if any of the characters inside the string are alphabets
return self.unicodeScalars.contains {CharacterSet.letters.contains($0)}
}
Please try.
edit/update: Xcode 11.4 • Swift 5.1
extension StringProtocol {
var containsLetters: Bool { contains { $0.isLetter } }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With