I'm using a UIDocument with iCloud. I'm not using CoreData. What's the best way to delete a UIDocument?
You can delete files you no longer want to store in iCloud Drive. Important: When you delete a file from iCloud Drive on iCloud.com, it's also deleted from all your devices that have iCloud Drive turned on.
Select the file or files you want to delete. Select Delete. The files move to the Recycle bin.
Copied from the "Deleting a Document" section of the Document-Based App Programming Guide for iOS.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
NSFileCoordinator* fileCoordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[fileCoordinator coordinateWritingItemAtURL:fileURL options:NSFileCoordinatorWritingForDeleting
error:nil byAccessor:^(NSURL* writingURL) {
NSFileManager* fileManager = [[NSFileManager alloc] init];
[fileManager removeItemAtURL:writingURL error:nil];
}];
});
N.B.: "When you delete a document from storage, your code should approximate what UIDocument does for reading and writing operations. It should perform the deletion asynchronously on a background queue, and it should use file coordination."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With