Created
July 22, 2013 18:17
-
-
Save rsaunders100/6056183 to your computer and use it in GitHub Desktop.
Demonstrates the various NSDataWritingOptions. Should be used with a program like iExplorer to see how these file behave. http://www.macroplant.com/iexplorer/
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
[MyClass writeStringWithFileName:@"Complete" | |
option:NSDataWritingFileProtectionComplete]; | |
[MyClass writeStringWithFileName:@"CompleteUnlessOpen" | |
option:NSDataWritingFileProtectionCompleteUnlessOpen]; | |
[MyClass writeStringWithFileName:@"CompleteUntilFirstUserAuthentication" | |
option:NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication]; | |
[MyClass writeStringWithFileName:@"None" | |
option:NSDataWritingFileProtectionNone]; | |
// ... | |
+ (void) writeStringWithFileName:(NSString *)fileName | |
option:(NSDataWritingOptions)option | |
{ | |
NSString * string = @"My sensitive data"; | |
NSData * data = [string dataUsingEncoding:NSUTF8StringEncoding]; | |
NSString * documentsPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; | |
NSString * path = [[documentsPath stringByAppendingPathComponent:fileName] stringByAppendingPathExtension:@"txt"]; | |
NSError * error = nil; | |
[data writeToFile:path | |
options:option | |
error:&error]; | |
NSAssert(!error, @"Error with writeToFile %@", error); | |
} | |
// .... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment