I connect a segue between a button and a view controller as shown in the screenshoot.

Everything works until I choose the class as "ViewController".

Every time I click the "Add" button, the code crashes with following error:"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"

I'm really confused now. Can anyone help me this?
You are getting crash bcoz table view is not connected as IBOutlet.
You need to connect table view IBOutlet in to view controller. You can do it by assistant editor top right corner (a double circle button intersecting each other) and drag and drop by pressing right click from table view to the view controller.
Once IBOutet is connected, in view controller there will be a dark gray color circle in before a property indicates that it will be connected successfully.

If circle is not filled then it means that property is not connected as IBOutlet.

See pic.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With