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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章