斯威夫特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