Swift2 Swift 2 iOS9文本大小写检查

Swift2 Swift 2 iOS9文本大小写检查,swift2,ios9,Swift2,Ios9,我试图为下面的示例找到一个解决方案。我已经创建了一个用户注册页面,我检查密码重置问题是否与实际密码不匹配(正常工作),但我要做的是将输入的密码和密码重置问题转换为小写,并检查是否不匹配。我更愿意在运行中执行此操作,而不是将密码放入var 这样做的原因是为了确保密码重置问题与实际密码不同,而不考虑特定字符的大小写 if (passWord.text) == (resetQuestion.text) { let alertController = UIAlertControl

我试图为下面的示例找到一个解决方案。我已经创建了一个用户注册页面,我检查密码重置问题是否与实际密码不匹配(正常工作),但我要做的是将输入的密码和密码重置问题转换为小写,并检查是否不匹配。我更愿意在运行中执行此操作,而不是将密码放入var

这样做的原因是为了确保密码重置问题与实际密码不同,而不考虑特定字符的大小写

    if (passWord.text) == (resetQuestion.text) {
        let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
            "password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
        self.presentViewController(alertController, animated: true, completion: nil)
        return
    }


    if String.lowercaseString.rangeOfString(passWord.text) == String.lowercaseString.rangeOfString(resetQuestion.text) {
        let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message: 
            "password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
        self.presentViewController(alertController, animated: true, completion: nil)
        return
    }

任何提示或帮助都将不胜感激。

有一种不区分大小写的比较方法,您可以尝试。差不多

if passWord.text.caseInsensitiveCompare(resetQuestion.text) == .OrderedSame {
        let alertController = UIAlertController(title: "PASSWORD SECURITY ISSUE", message:
        "password reset question must not match actual password!", preferredStyle: UIAlertControllerStyle.Alert)
    alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
    self.presentViewController(alertController, animated: true, completion: nil)
    return
}

谢谢你,卢克,效果很好。我只想补充一句!passWord.text和resetQuestion.text.String之后不是Swift中的类。小写字符串和大写字符串是实例属性,所以“Ab”。大写字符串==“Ab是真的,等等@DacrozThat's OK很高兴它起作用:)。我知道你必须打开这些值。