問題:
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