I have a function in my app delegate which appends an item to an array in my a file named ViewController.swift, and then I want to reload a tableview in that same file. I attempt to do so like so:
let vc = ViewController()
let navigationController = UINavigationController(rootViewController: vc)
window!.rootViewController = navigationController
println(vc.messages)
//1 vc.messages.append(message.data.message as! String)
//2 vc.MessageTableView?.reloadData()
The lines numbered 1,2 are where I set breakpoints. It appears to break after line numbered 2.
The exact error I get is
fatal error: unexpectedly found nil while unwrapping an Optional value
I believe my problem is that I am setting the root view controller incorrectly.
Edit #1
Window is declared up top.
If i run my code like this:
let vc = ViewController()
messages.append(message.data.message as! String)
vc.MessageTableView?.reloadData()
println(messages)
Then I can see that the correct data is put into the array (Which i made global for this scenario) but the table does not get updated in the View controller.
window
declared? Initialized? – Cu