斯威夫特2之前,我用這個擴展檢查字符串是否僅是做出來的數字:如何檢查一個字符串是否只包含Swift 2中的數字?
func isNumbersOnly() -> Bool {
let regexNumbersOnly = NSRegularExpression(pattern: ".*[^0-9].*", options: nil, error: nil)!
return regexNumbersOnly.firstMatchInString(self, options: nil, range: NSMakeRange(0, self.length())) != nil
}
但現在斯威夫特2我得到的錯誤
Cannot invoke initializer for type 'NSRegularExpression' with an argument list of type '(pattern: String, options: NilLiteralConvertible, error: NilLiteralConvertible)'
有沒有更好的已知的方式現在?日Thnx!
酷,tnx!如此多的變化...... – headkit
不客氣。確實。 – Moritz