Lui*_*Von 6 xcode swift swift3
我目前正在将我的代码转换为swift 3,并且我使用以下代码遇到上述错误.
 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)  } )
}
Run Code Online (Sandbox Code Playgroud)
任何善良的灵魂都可以为此提供帮助?
在Swift 3中,CharacterSet经过重新设计,可以很好地与UnicodeScalarUTF-8代码点配合使用.
在这种情况下,您可以编写如下内容:
var containsAlphabets: Bool {
    //Checks if any of the characters inside the string are alphabets
    return self.unicodeScalars.contains {CharacterSet.letters.contains($0)}
}
Run Code Online (Sandbox Code Playgroud)
请试试.
编辑/更新:Xcode 11.4 \xe2\x80\xa2\xc2\xa0Swift 5.1
\n\nextension StringProtocol {\n    var containsLetters: Bool { contains { $0.isLetter } }\n}\nRun Code Online (Sandbox Code Playgroud)\n
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           2973 次  |  
        
|   最近记录:  |