Skip to content

Instantly share code, notes, and snippets.

@rsaunders100
Created July 22, 2013 18:17
Show Gist options
  • Save rsaunders100/6056183 to your computer and use it in GitHub Desktop.
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/
[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