How to get a TextField value using Swift to create a Mac application

I was creating a Mac application using Swift. I have email as TextField and Password as SecureField. I need to get the email and password values ​​that I entered after running the code.

Now i tried how

@IBOutlet var Email: NSTextField!

@IBOutlet var Password: NSSecureTextField!


@IBAction func signin(sender: AnyObject) {

println("Email is: \(Email.objectValue) and password is: \(Password.objectValue)")
}

He returns me the output as

Email is: Optional(yashwanthbabu.gujarathi@gmail.com) and password is Optional(password)

I need to get only values ​​like

Email is: yashwanthbabu.gujarathi@gmail.com and Password is: password

I mean, I should not get "Optional" in the output.

+4
source share
1 answer

Looks like you do not want to objectValue, but the stringValuefields.

println("Email is: \(Email.stringValue) and password is: \(Password.stringValue)")
+6
source

Source: https://habr.com/ru/post/1568131/


All Articles