0

I'm getting Thread 1 EXC_BAD_INSTRUCTION ( ... ) error whne I try to retrieve the the text inside the TextField.

@IBOutlet weak var recordingTitle: UITextField!

audioFileTitle = recordingTitle.text

This is actually what I have and I get the EXC_BAD_INSTRUCTION on this.`

recordingTitle.text will cause the error to occur, what what am I doing here?

Thanks

rubyist
  • 389
  • 4
  • 22
  • Where in your code are you grabbing the text? – sooper Apr 16 '17 at 00:45
  • Can't you find **`Unexpectedly found nil`** in the debug console? – OOPer Apr 16 '17 at 03:22
  • The issue that the outlets to interface builder are not yet connected when `viewDidLoad` method is called. Place the `recordingTitle.text` in `viewWillAppear` or later and it should work. – TheAppMentor Apr 17 '17 at 14:24

2 Answers2

0

Creating an IBOutlet for a UITextField named as the title is a bad idea. Try using any other name which is not a sub-property. I am surprised you didn't get the errors via Xcode already as shown in the screenshot.enter image description here

Mukund Agarwal
  • 575
  • 5
  • 14
0

It sounds like the text field is being deallocated from memory as it is 'weak' and then crashes on it being nil when you try to access the text. can you show some more code on where you are actually calling recordingTitle.text etc.

Also is this in a view controller or xib, as that can affect how the view is setup and the outlets being connected correctly.

Joe Benton
  • 3,703
  • 1
  • 21
  • 17