Read data from property list
- (NSDictionary *) dictionaryWithPropertyListAtPath: (NSString *) path {
NSString *error = nil;
NSPropertyListFormat format;
NSData *plistXML = [ [NSFileManager defaultManager] contentsAtPath: path];
NSDictionary *result = (NSDictionary *) [NSPropertyListSerialization propertyListFromData: plistXML
mutabilityOption: NSPropertyListMutableContainersAndLeaves
format: &format
errorDescription: &error];
if (error != nil) {
NSLog(@"Error while reading plist: %@", error);
}
return result;
}
- (void) saveDictionary: (NSDictionary *) dictionary toPropertyListAtPath: (NSString *) path {
NSString *error = nil;
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList: dictionary
format: NSPropertyListXMLFormat_v1_0
errorDescription: &error];
if (plistData != nil) {
[plistData writeToFile: path atomically: YES];
} else {
NSLog(@"Error while writing plist: %@", error);
}
}
Discover more from mycodetips
Subscribe to get the latest posts sent to your email.