Skip to content

Instantly share code, notes, and snippets.

@aquarius
Created November 30, 2012 13:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquarius/a1086ed57b26cb292160 to your computer and use it in GitHub Desktop.
Save aquarius/a1086ed57b26cb292160 to your computer and use it in GitHub Desktop.
Rename iCloud Document
NSURL *sourceURL = document.fileURL;
NSURL *destinationURL = [[sourceURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:fileName isDirectory:NO];
NSError *writeError = nil;
__block NSError *moveError = nil;
__block BOOL success = NO;
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[coordinator coordinateWritingItemAtURL: sourceURL options: NSFileCoordinatorWritingForMoving writingItemAtURL: destinationURL options: NSFileCoordinatorWritingForReplacing error: &writeError byAccessor: ^(NSURL *newURL1, NSURL *newURL2) {
NSFileManager *fileManager = [[NSFileManager alloc] init];
success = [fileManager moveItemAtURL:newURL1 toURL:newURL2 error:&moveError];
if (success) [coordinator itemAtURL:newURL1 didMoveToURL:newURL2];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment