articles icon indicating copy to clipboard operation
articles copied to clipboard

iCloud and CoreData Article: Add section about when to Update UI

Open arnoappenzeller opened this issue 11 years ago • 4 comments

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.

arnoappenzeller avatar Mar 13 '14 00:03 arnoappenzeller

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!

chriseidhof avatar Aug 11 '14 10:08 chriseidhof

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

mbbischoff avatar Aug 11 '14 13:08 mbbischoff

Ping @mattbischoff =)

chriseidhof avatar Nov 20 '14 23:11 chriseidhof

I’ll PR it. Sorry for the delay.

mbbischoff avatar Nov 22 '14 16:11 mbbischoff