Created
April 15, 2015 13:06
-
-
Save laynemoseley/5fb41ca89eed62fb1ea1 to your computer and use it in GitHub Desktop.
Property List Serialization
This file contains hidden or 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
// 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