-
-
Save aquarius/a1086ed57b26cb292160 to your computer and use it in GitHub Desktop.
Rename iCloud Document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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