2016-03-22 4 views
0

次の例の解決策を見つけようとしています。私はユーザー登録ページを作成して、パスワードリセットの質問が実際のパスワードと一致しないことを確認します(問題なく動作します)が、入力したパスワードとパスワードリセットの質問を小文字に変換し、一致。私は、パスワードをvarに入れるのではなく、その場でこれを行うことを好むでしょう。スウィフト2 iOS9テキストケースチェック

これは、特定の文字の大文字と小文字を区別せずに、パスワードリセットの質問が実際のパスワードと同じでないことを確認するためです。

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 
    } 

何か指摘や助けをいただければ幸いです。

答えて

-1

試すことができるcaseInsensitiveCompareメソッドがあります。何かが好きです。

+0

ありがとうございました。私はちょうど追加しなければならなかった! passWord.textとresetQuestion.textの後に – dacrozz

+0

文字列はSwiftのクラスではありません。 lowercaseStringとuppercaseStringはインスタンスのプロパティなので、 "Ab" .uppercaseString == "ABはtrueなどです。 – user3441734

+0

@dacrozzそれはうまくいきました:)私はあなたが値をラップしていないのを見ています。 –

関連する問題