cocoa-touchicloudconflictuidocumentnsfileversion

Is the method removeAndReturnError: not necessary?


I've just read the documentation about conflict resolution with UIDocuments in the iCloud: Resolving Document Version Conflicts

In the last point of the chapter "How to Tell iOS That a Document Version Conflict Is Resolved" is written:

Remove the resolved versions of the document. For any versions you no longer need, call the removeAndReturnError: method of NSFileVersion to reclaim the storage for the file. Document revisions remain on the server until you delete them.

But in the code sample "Listing 6-3" there is no removeAndReturnError: method called. Is this method not necessary or where should I call it?

Thanks for any help

Linard


Solution

  • removeAndReturnError or removeOtherVersionsOfItemAtURL is necessary to free iCloud storage space.

    The following line in Listing 6-3 removes all versions except for the current version, instead of removeAndReturnError:.

    [NSFileVersion removeOtherVersionsOfItemAtURL:_document.fileURL error:nil];
    

    But, Listing 6-3 code seems to be strange a little. Because removeOtherVersionsOfItemAtURL: removes all versions, unresolvedConflictVersionsOfItemAtURL: at the next line always returns an empty array, then inside of the loop (fileVersion.resolved = YES;) is never executed.

    My code in an application is like this. I am not sure it is necessary that "resolved" property is set to YES before it is removed, but I thought this might be safer.

    NSArray* conflictVersions = [NSFileVersion unresolvedConflictVersionsOfItemAtURL:fileURL];
    for (NSFileVersion* fileVersion in conflictVersions) {
        fileVersion.resolved = YES;
        NSError* error = nil;
        [fileVersion removeAndReturnError:&error];
    }