-6

In my AddViewController, I have this code:

override func viewDidLoad() {
super.viewDidLoad()
    // Do any additional setup after loading the view.

    eventTextField.userInteractionEnabled=false
    dateTextField.userInteractionEnabled=false
    detailsTextField.userInteractionEnabled=false

    eventTextField.text=eventData.objectForKey("eventtitle") as! String
    dateTextField.text=eventData.objectForKey("eventdate") as! String
    detailsTextField.text=eventData.objectForKey("eventdetails") as! String

}

But then when I run the app, this error comes up saying, "Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" on this line:

eventTextField.text=eventData.objectForKey("eventtitle") as! String

Then in the debug area, it says,

fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

Any way to debug this?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
JW Developer
  • 123
  • 1
  • 8
  • 7
    What do you think the error message "unexpectedly found nil while unwrapping an Optional value" on a statement: `eventData.objectForKey("eventtitle")`? Really think, you are allowed to consult documentation. Then also this is curreently one of the most popular errors found on SO there are litterally humbreds of appropriatre answers on SO. – zaph Sep 07 '15 at 20:25

1 Answers1

0

The eventData dictionary does not contain an eventtitle key. The lookup contains a nil value which you force unwrap / cast using as!. This is the reason behind the error message.

As a rule, do not use force unwrap unless you are absolutely sure that the value you're unwrapping is never nil.

Aderstedt
  • 6,301
  • 5
  • 28
  • 44