in the UIViewController
's viewDidLoad()
there is a method being called for updating a class variable. Once I navigate to another view controller and come back to this one, UITableView
's delegate methods are being called first where that class variable is being used. App is crashing because that variable is being constructed in viewDidLoad()
. How can this issue be fixed? Thank you.
the class variable in question:
var showHideDict = Dictionary<Int, Bool>()
the viewDidLoad()
:
override func viewWillAppear() {
super.viewWillAppear()
makeAPICall()
}
the API calling method:
func makeAPICall() {
// create helper object
let helper = ModelHelper()
helper.createModels(receivedDict: result! as NSDictionary)
// store the showHideDict
for index in 0...(Modelclass.models.count - 1) {
self.showHideDict[index] = true
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}