OK, my code looks a bit different, I have it in a separate class to reuse it for all my projects. However, if iCloud is enabled (URLForUbiquityContainerIdentifier: nil return not nil), I configure my NSPsistentStoreCoordinator as follows:
// ---- iCloud Setup // fist container in entitlements NSURL *iCloudDirectoryURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil]; // if iCloud is enabled setup the store if (iCloudDirectoryURL) { __iCloudEnabled = true; NSLog(@"iCloud:%@", [iCloudDirectoryURL absoluteString]); // AppDelegate has to provide the contentnamekey NSString *contentNameKey = [appDelegate dataStoreContentNameKey]; options = [NSDictionary dictionaryWithObjectsAndKeys:contentNameKey, NSPersistentStoreUbiquitousContentNameKey, iCloudDirectoryURL, NSPersistentStoreUbiquitousContentURLKey, nil]; }
I am skipping where you are setting up NSPersistentStoreUbiquitousContentNameKey.
Secondly, I understand that this only works on the device, and your app ID should include iCloud.
source share