简体   繁体   中英

In Swift, why do I get an error when trying to Println textfield.text

I know it gives me an 'explanation,' but I still don't really understand it.

I'm trying to print the contents of my UITextField each time it's updated.

Here's my code:

@IBAction func textUpdated(sender: UITextField) {
        println("textFieldtext = %@", sender.text);
}

I get an error: Cannot invoke 'println' with an argument list of type '(StringLiteralConvertible, @Ivalue String!)'

What does that mean? What can I do to print this?

Try using this instead:

println("textFieldText = \\(sender.text)")

This is called String Interopelation and it allows you to build a new string from various different types. The way you are doing it doesn't work because println only takes one argument.

EDIT: Added an explanation based on the info from the comments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM