replacementOccurrences无法在Device上运行

时间:2018-02-14 06:04:27

标签: ios swift

我修改了空格代码以删除文本字段输入中的空格,但这是一个问题,在模拟器上它工作正常并删除空格但在设备上,它根本不起作用我的代码:< / p>

var number = numberTxtField.text
if number!.hasPrefix("+98") {
    let start = number!.index(number!.startIndex, offsetBy: 0);
    let end = number!.index(number!.startIndex, offsetBy: 3);
    number!.replaceSubrange(start..<end, with: "0")
    self.trimmed = number!.replacingOccurrences(of: " ", with: "")
    print(self.trimmed)
    let pattern = "^[0-9]+$"
    let predicate = NSPredicate(format: "self MATCHES [c] %@", pattern)
    if predicate.evaluate(with: self.trimmed) {
        print("Valid")
        if self.trimmed == nil && self.trimmed == "" {
            return
        }
        numberTxtField.resignFirstResponder()
        self.view.endEditing(true)
        SendNumber()
    }
}

当我在模拟器上输入+98 912 123 1234时,它会返回09121231234,当我在设备上执行此操作时,它会返回0 912 123 1234

有谁知道为什么?

this is my result on my device (iPhone 6s with ios 11.2.5):

this is my result on the emulator (iPhone 8 iOS 11.2):

0 个答案:

没有答案