DictionaryWithContentsOfFile from file line

I want to load NSDictionaryfrom plist, and I have a plist line in memory, I don't have a plist file. NSDictionary dictionaryWithContentsOfFile:accepts only the file name; it does not accept the file string. How can I upload NSDictionaryusing a plist file?

+3
source share
1 answer

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];
+5
source

All Articles