Core Data + iCloud: clear data folders for syncing

This content has 9 years. Please, read this page keeping its age in your mind.

When you are developing an iCloud app and you have problems with syncing try the above code:

<code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
BOOL cleanUbiquitousFolder = YES;
if (cleanUbiquitousFolder)
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtURL:[fileManager URLForUbiquityContainerIdentifier:nil] error:nil];

return NO;
// Your app code here.

return YES;
All you need to do is run it once with “cleanUbiquitousFolder = YES” and the switch it back to NO to resume developing your app.
Credits to apple developer forums…