问题:
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