Hi I hope somebody can help me out with this. When a user first logs into my application, an API call is made which will fetch existing data for that user in a database on the web server. When they first log in (if successful) I segue to another viewcontroller that displays a progress indicator which stops animating when the downloaded data is fully saved to Core Data, then segue's to the main vc of the app (where the user can start using the app).
Instead of having a progress indicator, I would rather have a real time indicator like a count of currently downloaded items that gets updated each time an item is saved to core data, but in this case I have no choice but to use NSNotificationCenter to listen for when each item downloaded from the API is saved to core data. So far I have:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
NSNotificationCenter.defaultCenter().addObserver(self, selector:"contextDidSave:", name: NSManagedObjectContextDidSaveNotification, object:nil)
}
func contextDidSave(notification: NSNotification) {
if notification.name == NSManagedObjectContextDidSaveNotification {
var c = CoreMessage.getMessages(self.moc, ascending:true).count
//the println works - i see the updated count
println(c)
//this doesnt work, the lbl does not get updated
self.labelCount.text = "\(c)"
}
}
I also tried to update the lable like this:
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.labelCount.text = "\(c)"
})
Can anybody shed a light on what I might be doing wrong?