user663896
user663896

Reputation:

Read binary plist into NSDictionary

Is there simple way to parse the binary plist file into the NSDictionary representation? I am searching something like that:

NSString* strings = [NSString stringWithContentsOfURL: ... encoding: NSUnicodeStringEncoding error: ...];
NSMutableDictionary* pairs = (NSMutableDictionary*)[strings propertyListFromStringsFileFormat];

Using this code caused the exception while parsing the binary plist file.

Upvotes: 2

Views: 3655

Answers (2)

Axel
Axel

Reputation: 966

Considering a file called DataStorageFile.plist, you can use:

NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"DataStorageFile" ofType:@"plist"];
self.data = [NSDictionary dictionaryWithContentsOfFile:dataPath];

If you want an array:

self.data = [NSArray arrayWithContentsOfFile:dataPath];

Upvotes: 3

tonklon
tonklon

Reputation: 6767

Are you looking for [NSDictionary dictionaryWithContentsOfFile:]?

Upvotes: 9

Related Questions