3

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.

2
  • 1
    Can u post more Code? You can access your textfield with: let textField = alert.textFieldAtIndex(0) Commented Jul 31, 2014 at 21:13
  • Yeah, could you post the code where you grab the text field and println it? Commented Jul 31, 2014 at 22:01

1 Answer 1

4

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) 
Sign up to request clarification or add additional context in comments.

1 Comment

'[AnyObject]?' does not have a member named 'subscript' so use ! before [0]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.