Skip to content

Instantly share code, notes, and snippets.

@stephsharp
Last active December 18, 2015 11:58
Show Gist options
  • Save stephsharp/5778921 to your computer and use it in GitHub Desktop.
Save stephsharp/5778921 to your computer and use it in GitHub Desktop.
Snippet to read data from a property list
// Helpful tutorial:
// http://www.theappcodeblog.com/2011/05/30/property-list-tutorial-using-plist-to-store-user-data/
// Get property list from main bundle
NSString * plistPath = [[NSBundle mainBundle] pathForResource:@"PListName" ofType:@"plist"];
// Read property list into memory as an NSData object
NSData * plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSString * errorDesc = nil;
NSPropertyListFormat format;
// Convert static property list into dictionary object
NSDictionary * temp = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorDesc];
if (!temp)
NSLog(@"Error reading plist: %@, format: %d", errorDesc, format);
// Use data from property list
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment