How to read data from property list file (.plist) to NSDictionary in IOS.

 

- (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);
}
}