{"action":"created","issue":{"url":"https://api.github.com/repos/magicalpanda/MagicalRecord/issues/1054","labels_url":"https://api.github.com/repos/magicalpanda/MagicalRecord/issues/1054/labels{/name}","comments_url":"https://api.github.com/repos/magicalpanda/MagicalRecord/issues/1054/comments","events_url":"https://api.github.com/repos/magicalpanda/MagicalRecord/issues/1054/events","html_url":"https://github.com/magicalpanda/MagicalRecord/issues/1054","id":98169071,"number":1054,"title":"Async CoreData stack initialization when using iCloud","user":{"login":"pronebird","id":704044,"avatar_url":"https://avatars.githubusercontent.com/u/704044?v=3","gravatar_id":"","url":"https://api.github.com/users/pronebird","html_url":"https://github.com/pronebird","followers_url":"https://api.github.com/users/pronebird/followers","following_url":"https://api.github.com/users/pronebird/following{/other_user}","gists_url":"https://api.github.com/users/pronebird/gists{/gist_id}","starred_url":"https://api.github.com/users/pronebird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pronebird/subscriptions","organizations_url":"https://api.github.com/users/pronebird/orgs","repos_url":"https://api.github.com/users/pronebird/repos","events_url":"https://api.github.com/users/pronebird/events{/privacy}","received_events_url":"https://api.github.com/users/pronebird/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-30T13:28:22Z","updated_at":"2015-07-31T08:00:10Z","closed_at":null,"body":"Hi,\r\n\r\nFrom time to time when I start my app I get a blank table view controller because FRC reports there are no objects. Although if I force refresh from interface and re-create FRC then data shows up.\r\n\r\nI have a very simple configuration for iCloud:\r\n\r\n```objc\r\n- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\r\n    [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelVerbose];\r\n    [MagicalRecord setupCoreDataStackWithiCloudContainer:nil contentNameKey:nil localStoreNamed:@\"CoreData.sqlite\" cloudStorePathComponent:nil completion:^{\r\n        [self _addSeedData]; // added only once on first load\r\n    }];\r\n}\r\n```\r\n\r\nLog:\r\n\r\n```\r\nCreated new private queue context: <NSManagedObjectContext: 0x7c46a860>\r\nCreated new context Untitled Context with store coordinator: <NSPersistentStoreCoordinator: 0x7bf845d0>\r\nSet root saving context: <NSManagedObjectContext: 0x7c46a860>\r\nCreated new main queue context: <NSManagedObjectContext: 0x7beb0c60>\r\nSet default context: <NSManagedObjectContext: 0x7beb0c60>\r\nTimeline: viewDidLoad, fetchedObjects.count = 0\r\niCloud is not enabled\r\nCreated new private queue context: <NSManagedObjectContext: 0x7c1bc570>\r\nCreated new private queue context: <NSManagedObjectContext: 0x7c1adf40>\r\nCreated new private queue context: <NSManagedObjectContext: 0x7c1927c0>\r\nNO CHANGES IN ** saveWithBlockAndWait: ** CONTEXT - NOT SAVING\r\nNO CHANGES IN ** saveWithBlockAndWait: ** CONTEXT - NOT SAVING\r\nNO CHANGES IN ** Untitled Context ** CONTEXT - NOT SAVING\r\n```\r\n\r\nFRC setup:\r\n\r\n```objc\r\n- (void)viewDidLoad {\r\n    [super viewDidLoad];\r\n    NSFetchedResultsController *controller = [ExpenseModel MR_fetchAllSortedBy:@\"placedAt\" ascending:NO withPredicate:nil groupBy:@\"monthYearSection\" delegate:self];\r\n    self.fetchController = controller;\r\n}\r\n```\r\n\r\nLooking at this:\r\n\r\nhttps://github.com/magicalpanda/MagicalRecord/blob/c7b14f658b4fca32f8d33f8f76160203053ce4b9/MagicalRecord/Categories/NSPersistentStoreCoordinator%2BMagicalRecord.m#L147\r\n\r\nSo the whole iCloud setup is asynchronous that's why my root VC does not get any data when it creates FRC, because there is simply no storage added to CD stack at that point yet.\r\n\r\nSo if I comment dispatch_async and make the whole iCloud setup synchronously then everything works. I can assume that async queue was used to avoid any kind of locking of the main thread but reading objc.io (http://www.objc.io/issues/10-syncing-data/icloud-core-data/#asynchronous-persistent-store-setup) it seems that iCloud does not work that way anymore since iOS 7.\r\n\r\n> In iOS 7, calling addPersistentStoreWithType:configuration:URL:options:error: with iCloud options now returns a store almost immediately.\r\n>\r\n> In previous OS versions, this method wouldn’t return until iCloud data was downloaded and merged into the persistent store. This would cause significant delays, meaning that any calls to the method would need to be dispatched to a background queue. Thankfully, this is no longer necessary.\r\nMost likely this wouldn't work on iOS 6.1 which is still a deployment target for MagicalRecord.\r\n\r\nI would appreciate any suggestion or workaround to this problem."},"comment":{"url":"https://api.github.com/repos/magicalpanda/MagicalRecord/issues/comments/126599325","html_url":"https://github.com/magicalpanda/MagicalRecord/issues/1054#issuecomment-126599325","issue_url":"https://api.github.com/repos/magicalpanda/MagicalRecord/issues/1054","id":126599325,"user":{"login":"pronebird","id":704044,"avatar_url":"https://avatars.githubusercontent.com/u/704044?v=3","gravatar_id":"","url":"https://api.github.com/users/pronebird","html_url":"https://github.com/pronebird","followers_url":"https://api.github.com/users/pronebird/followers","following_url":"https://api.github.com/users/pronebird/following{/other_user}","gists_url":"https://api.github.com/users/pronebird/gists{/gist_id}","starred_url":"https://api.github.com/users/pronebird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pronebird/subscriptions","organizations_url":"https://api.github.com/users/pronebird/orgs","repos_url":"https://api.github.com/users/pronebird/repos","events_url":"https://api.github.com/users/pronebird/events{/privacy}","received_events_url":"https://api.github.com/users/pronebird/received_events","type":"User","site_admin":false},"created_at":"2015-07-31T08:00:10Z","updated_at":"2015-07-31T08:00:10Z","body":"If you have any suggestion for patch, then I could do that."}}