Here is my two cents on the issue. I tried what dtrotzjr recommended and didn't have a whole lot of success. It seems that removeUbiquitousContentAndPersistentStoreAtURL:options:error: is great for clearing out data in a UIManagedDocument, but the Logs folder is still there and so are the remnants of the file I'm trying to delete. Here is a simpler method for completely deleting a UIManagedDocument from iCloud or Local Docs:
+ (void)deleteDocumentURL:(NSURL *)url{
//if we have an iCloud Document, remove it from the UbiquitouseKeyValueStore
if ([self isiCloudURL:url]) {
[[NSUbiquitousKeyValueStore defaultStore] removeObjectForKey:[url lastPathComponent]];
}
//do the delete on another thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
NSError *coordinationError;
[coordinator coordinateWritingItemAtURL:url
options:NSFileCoordinatorWritingForDeleting
error:&coordinationError
byAccessor:^(NSURL *newURL) {
NSError *removeError;
//code for performing the delete
[[NSFileManager defaultManager] removeItemAtURL:newURL error:&removeError];
//if we have an iCloud file...
if ([self isiCloudURL:url]) {
//remove log files in CoreData directory in the cloud
NSURL *changeLogsURL = [[self urlForiCloudLogFiles] URLByAppendingPathComponent:[url lastPathComponent]];
[[NSFileManager defaultManager] removeItemAtURL:changeLogsURL error:&removeError];
}
}];
});
}
This is pretty much the code from Stanford's CS193 course 2012 + the delete for the changeLogs folder and it works on local and iCloud docs. Please let me know if you see any issues with performing the delete this way.