I have UIDocumentwith the name "Old." I made some changes and would like to keep it under the name "New." The content of the "Old" should not be changed. Here is my unsuccessful attempt:
First, copy the unsaved "Old" document into the "New" file. Save the "Old" document to the "New" file. Theoretically, since the "old" document was never stored in its URL in the file system, it should still be in the "old" state. The "new" file location must have the latest changes in the "Old" because we just saved the "Old" document in the "new" file location.
NSFileManager *manager = [NSFileManager defaultManager];
NSURL *newFileLocation = [documentDirectoryURL URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", document.title, DOCUMENT_EXTENSION]];
NSURL *oldFileLocationCopy = document.fileURL.copy;
NSError *error;
BOOL copySuccess = [manager copyItemAtURL:oldFileLocationCopy toURL:newFileLocation error:&error];
if (! copySuccess)
{
NSLog(@"File not successfully copied.");
return;
}
[document saveToURL:newFileLocation forSaveOperation:UIDocumentSaveForOverwriting completionHandler:^(BOOL success)
{
if (success)
{
handler();
}
else
{
NSLog(@"New file rename not saved.");
}
}];
- . "" , "" .
, , SO. !