iCloud and CoreData Article: Add section about when to Update UI
The iCloud and CoreData Article is in fact pretty good but for me there was one thing missing.
I wondered how to figure out when to update the UI when an App is first launched and the iCloud Store is filled with data. I tought listening for the Notification in storesWillChange: would be enough. In fact you need to update when the storeDidChange: like this (otherwise the managedObjectContext would still be different to the iCloud content):
- (void)storesDidChange:(NSNotification *)note {
//check if iCloud is imported
NSNumber *storeVal = [note.userInfo objectForKey:NSPersistentStoreUbiquitousTransitionTypeKey];
if (storeVal.integerValue == NSPersistentStoreUbiquitousTransitionTypeInitialImportCompleted) {
NSLog(@"On iCloud Store now");
//ensure that the UI will be updated d on the mainthread for UI threadsafety otherwise
//this will cause a lot of trouble...
dispatch_async(dispatch_get_main_queue(), ^{
//update UI });
}
}
I'm not sure if this was the focus of the article or I didn't read it carefully enough but maybe it's worth a consideration.
Thanks! And sorry for only getting back to this now. Maybe you could submit a pull request, or maybe @bcapps or @mattbischoff could have a look at this? I think it'll be nice to include!
I'll take a look tonight.Matt
On Mon, Aug 11, 2014 at 6:38 AM, Chris Eidhof [email protected] wrote:
Thanks! And sorry for only getting back to this now. Maybe you could submit a pull request, or maybe @bcapps or @mattbischoff could have a look at this? I think it'll be nice to include!
Reply to this email directly or view it on GitHub: https://github.com/objcio/articles/issues/6#issuecomment-51764804
Ping @mattbischoff =)
I’ll PR it. Sorry for the delay.