user66 user66 - 2 months ago 20
Swift Question

Swift 3 conversion : value of type 'characterset' has no member 'characterIsMember'

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?

Answer

You can do as follow:

extension String {
    var containsAlphabets: Bool {
       return utf16.contains { (CharacterSet.letters as NSCharacterSet).characterIsMember($0) }
    }
}
Comments