Skip to content

Instantly share code, notes, and snippets.

@laynemoseley
Created April 15, 2015 13:06
Show Gist options
  • Save laynemoseley/5fb41ca89eed62fb1ea1 to your computer and use it in GitHub Desktop.
Save laynemoseley/5fb41ca89eed62fb1ea1 to your computer and use it in GitHub Desktop.
Property List Serialization
// NSArray and NSDictionary have methods to write to files using the .plist format
// If your array/dictionary only contains NSNumber, NSDate, NSData or NSString objects, this works like a charm!
NSArray *strings = @[@"stringOne", @"stringTwo"];
NSString *filePath = @"/Path/To/Documents/data.plist";
BOOL successfullyWroteFile = [strings writeToFile:filePath atomically:YES];
// For error handling, you can check the successfullWroteFile variable
// If you later need to get this data back, there are methods to read a plist back into an NSArray or NSDictionary
NSArray *strings = [NSArray arrayWithContentsOfFile:filePath];
// Cool eh?
// I use this sometimes when I need to persist really simple data structures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment