Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dictionaryWithContentsOfFile from the file string

I want to load a NSDictionary from a plist and I have the plist string in memory, I don't have the plist file. NSDictionary dictionaryWithContentsOfFile: only accepts file name, it won't accept file string. How can I load the NSDictionary with a plist file?

like image 922
Dani Avatar asked Jun 06 '26 21:06

Dani


1 Answers

Here you go...

NSData * data = [yourString dataUsingEncoding:NSUTF8StringEncoding];

NSString *errorDesc = nil;
NSPropertyListFormat format;
NSDictionary * dict = (NSDictionary*)[NSPropertyListSerialization
                                      propertyListFromData:data
                                      mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                      format:&format
                                      errorDescription:&errorDesc];
like image 195
Simon Lee Avatar answered Jun 10 '26 03:06

Simon Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!