master22
master22

Reputation: 37

Access textfield of UIAlertController - swift ios8

I'm trying to access the text field of a UIAlertView and I'm using the textFields property and I get the following output from the textFields property:

<_UIAlertControllerTextField: 0x7fe911f96790; 
frame = (4 4; 231 16);  
text = 'THIS IS THE TEXT THAT I JUST ENTERED';  
clipsToBounds = YES; opaque = NO;  
gestureRecognizers = <NSArray: 0x7fe914215cc0>;  
layer = <CALayer: 0x7fe911f96c40>>

As you can see the text does show up, but I need the text separately. textFields.text won't work because its deprecated and cannot be used in Swift.

Upvotes: 3

Views: 1144

Answers (1)

Connor
Connor

Reputation: 64694

The textFields are stored in an Array of AnyObject. If you want to access text you should cast it as a UITextField first:

((alert.textFields[0] as UITextField).text)

Upvotes: 4

Related Questions