0

I am new to Swift, and I'm trying to make a login program for Mac OS X. I do know about Swift programming on iOS, but I don't know that much about OS X Swift. So I wrote a program for OS X. I almost finished it, but I need to know how to check whether the text fields are empty or not. In iOS, you can do this using the .isempty property. It doesn’t work on OS X though. How can I do this?

class InsideViewController: NSViewController {

    @IBOutlet var userNametext: NSTextField!
    @IBOutlet var passwordtext: NSSecureTextField!
    @IBOutlet var conformpasswordtext: NSSecureTextField!


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: AnyObject? {
        didSet {
            // Update the view, if already loaded.
        }
    }

    @IBAction func SignUpButton(sender: NSButton) {
        let userName = userNametext.stringValue
        let userPassword = passwordtext.stringValue
        let userPasswordcon = conformpasswordtext.stringValue

        NSUserDefaults.standardUserDefaults().setObject(userName, forKey: "username")
        NSUserDefaults.standardUserDefaults().setObject(userPassword, forKey: "userpassword")
        NSUserDefaults.standardUserDefaults().synchronize()

        if (userNametext.isempty)
    }

}
brimstone
  • 3,370
  • 3
  • 28
  • 49
RockNav
  • 79
  • 2
  • 8
  • "but I need to know how to check whether the text fields are empty or not. In iOS, you can do this using the .isempty property" No. `.isEmpty` tells you whether a _string_ is empty, not whether a text field is empty. – matt Apr 09 '15 at 23:37

1 Answers1

0
if userNametext.stringValue == "" {
    //Action
}

As seen here you can access the text of the NSTextField using the stringValue property, which can also be used to modify the text.

Community
  • 1
  • 1
brimstone
  • 3,370
  • 3
  • 28
  • 49