What is the Swift equivalent of isEqualToString in Objective-C?

問題:

I am trying to run the code below:我正在嘗試運行以下代碼:

import UIKit

class LoginViewController: UIViewController {

@IBOutlet var username : UITextField = UITextField()
@IBOutlet var password : UITextField = UITextField()

@IBAction func loginButton(sender : AnyObject) {

    if username .isEqual("") || password.isEqual(""))
    {
        println("Sign in failed. Empty character")
    }
}

My previous code was in Objective-C, which was working fine:我以前的代碼是在 Objective-C 中的,它運行良好:

 if([[self.username text] isEqualToString: @""] ||
    [[self.password text] isEqualToString: @""] ) {

I assume I cannot use isEqualToString in Swift.我假設我不能在 Swift 中使用isEqualToString Any help would be appreciated.任何幫助,將不勝感激。


解決方案:

參考一: https://en.stackoom.com/question/1d6ea
參考二: https://stackoom.com/question/1d6ea
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章