Created
September 10, 2011 14:39
-
-
Save dlinsin/1208372 to your computer and use it in GitHub Desktop.
Simple category to read plist as array
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
#import "NSArray+Plist.h" | |
@implementation NSArray (Plist) | |
+ (id)arrayFromPlist:(NSString *)filename { | |
NSData *plistData; | |
NSString *error; | |
NSPropertyListFormat format; | |
id plist; | |
NSString *localizedPath = [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"]; | |
plistData = [NSData dataWithContentsOfFile:localizedPath]; | |
plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error]; | |
if (!plist) { | |
NSLog(@"Error reading plist from file '%s', error = '%s'", [localizedPath UTF8String], [error UTF8String]); | |
[error release]; | |
} | |
return plist; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment