Advertisements
NSFileVersion by example
Getting the Version of a File
+ currentVersionOfItemAtURL:
Returns the most recent version object for the file at the specified URL.
Example
NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; NSURL *fileURL = [directoryURL URLByAppendingPathComponent:@"backupEezy/test.txt"]; NSLog(@"%@",[NSFileVersion currentVersionOfItemAtURL:fileURL].URL); NSLog(@"%@",[NSFileVersion currentVersionOfItemAtURL:fileURL].localizedName); NSLog(@"%@",[NSFileVersion currentVersionOfItemAtURL:fileURL].localizedNameOfSavingComputer); NSLog(@"%@",[NSFileVersion currentVersionOfItemAtURL:fileURL].modificationDate); NSLog(@"%@",[NSFileVersion currentVersionOfItemAtURL:fileURL].persistentIdentifier); NSLog(@"%d",[NSFileVersion currentVersionOfItemAtURL:fileURL].conflict); NSLog(@"%d",[NSFileVersion currentVersionOfItemAtURL:fileURL].resolved);
Output
2014-04-12 13:37:47.782 iOS-Tutorial[1322:a0b] file:///Users/rajkumar/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/D6203A56-1113-4762-A533-D7AA6AB60356/Documents/backupEezy/test.txt 2014-04-12 13:37:47.811 iOS-Tutorial[1322:a0b] test.txt 2014-04-12 13:37:47.813 iOS-Tutorial[1322:a0b] (null) 2014-04-12 13:37:47.814 iOS-Tutorial[1322:a0b] 2014-04-12 07:22:51 +0000 2014-04-12 13:37:47.815 iOS-Tutorial[1322:a0b] { } 2014-04-12 13:37:47.815 iOS-Tutorial[1322:a0b] 0 2014-04-12 13:37:47.816 iOS-Tutorial[1322:a0b] 1
+ otherVersionsOfItemAtURL:
Returns all versions of the specified file except the current version.
Example
NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; NSURL *fileURL = [directoryURL URLByAppendingPathComponent:@"backupEezy/test.txt"]; NSLog(@"%@",[NSFileVersion otherVersionsOfItemAtURL:fileURL]);
Output
2014-04-12 13:38:36.547 iOS-Tutorial[1336:a0b] (null)
+ versionOfItemAtURL:forPersistentIdentifier:
Returns the version of the file that has the specified persistent ID.
Example
NSFileManager *fileManager = [NSFileManager defaultManager]; NSURL *directoryURL = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; NSURL *fileURL = [directoryURL URLByAppendingPathComponent:@"backupEezy/test.txt"]; NSLog(@"%@",[NSFileVersion versionOfItemAtURL:fileURL forPersistentIdentifier:nil].localizedName);
Output
2014-04-12 13:41:36.892 iOS-Tutorial[1361:a0b] test.txt
Advertisements