Simon Guldstrand
Simon Guldstrand

Reputation: 488

'text' is unavailable: APIs deprecated as of iOS7... How to get text value from alert.textFields[0]?

My code was like this before updating to Xcode6-beta3:

cell.text = rowData["list_name"] as String

I have updated this to:

cell.textLabel.text = rowData["list_name"] as String

but this part of the code:

let alertText = alert.textFields[0].text

I can't understand how to get text from textFields[0] without using .text

Thanks in advance for any help!

EDIT:

Now with the GM version of Xcode I get this error instead. enter image description here

Would be super happy for a response, getting tired of changing this now :P

Also, how would you be able to decrypt that kind of error message? Could be good to know.

Thanks

Upvotes: 0

Views: 2475

Answers (1)

Martin R
Martin R

Reputation: 539975

The problem is that alert.textFields has the type [AnyObject] (corresponding to the Objective-C id), so that the compiler does not know that alert.textFields[0] is a UITextField which has a text method.

This should work:

let alertText = (alert.textFields[0] as UITextField).text

Upvotes: 2

Related Questions