0

I'm getting the following error.

fatal error: unexpectedly found nil while unwrapping an Optional value

The application is crashing on the following bit of code. Since it is my first scene, the app crashes the moment it loads.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    tableView.delegate = self
    tableView.dataSource = self
    mySingleton = Singleton.sharedInstance
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    tableView.reloadData()
}

It crashes on tableView.delegate = self. If I comment out that line and the tableView.delegate = self it then crashes on the tableView.reloadData() line. If I comment that line out the app no longer crashes but the dynamic tableView will no longer display data because it is not getting reloaded anymore.

The application was working perfectly until I added a 3rd tab to the tab bar view controller. It is possible that I accidentally did something else in the process. I would love to hear your thoughts on the matter. I have been staring at it for hours now.

Thanks, Alex

Hemang
  • 26,840
  • 19
  • 119
  • 186
Alex Cauthen
  • 497
  • 5
  • 12
  • 32
  • make sure you connected the table view to IBOutlet or initialized the tableView before using it. – Johnykutty Jan 20 '16 at 05:11
  • It is connected to an IBOutlet. It was actually working perfectly a few hours ago. I can't exactly initialize the tableView before opening the app because it is meant to display no data until at a later time. – Alex Cauthen Jan 20 '16 at 05:14
  • Try to reconnect IBOutlet of UITableView. – technerd Jan 20 '16 at 05:15
  • Please show more code of Singleton.sharedInstance and table's delegate methods? – Dharmbir Singh Jan 20 '16 at 05:16
  • For some reason performing a clean build has solved the problem. I do not know why. – Alex Cauthen Jan 20 '16 at 05:17
  • Possible duplicate of [What does "fatal error: unexpectedly found nil while unwrapping an Optional value" mean?](http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu) – jtbandes Jan 20 '16 at 07:25

2 Answers2

0

It seems that your tableview property is nil.

may be tableview is not connected properly as IBOutlet ...

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
0

Remove tableView outlet and try it again, to connect your tableView to your UIViewController.

Also, you can try typing in the logs(in case of crash):

po tableView

to see detailed info

iamalizade
  • 228
  • 1
  • 5