Reputation: 43
I see that this method is deprecated:
[[NSDictionary alloc] initWithContentsOfFile: url.path];
If I'm trying to read in the contents of a plist to create this dict, does anyone know what the proper new way is to do it?
Thanks!
Upvotes: 1
Views: 1430
Reputation: 285250
Nowadays it's highly recommended to use NSPropertyListSerialization
NSURL *url = [NSURL fileURLWithPath:@"/Users/myUser/path/to/foo.plist"];
NSError *error;
NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error];
NSDictionary *dictionary = [NSPropertyListSerialization propertyListWithData:data options:0 format:nil error:&error];
if (error) {
// handle error
} else {
NSLog(@"%@", dictionary);
}
Upvotes: 4