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

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

tips & tricks

Join 7,715 other subscribers

interview questions


Algorithm Android Android Studio API APP Programming Apps AS400 blogging Browser CheatSheets Config CSS DATABASE dsa error Features GUI HTML HTML5 IDE installation Interview Questions IOS iPhone javascript Mac objective-c OneDrive OS Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode


Archives

One response to “How to read data from property list file (.plist) to NSDictionary in IOS.”

  1. Birju Purushottam

    Hi Ranjan,
    Loved your tips. I am in urgent need to hire a person like you for my company. Can you please get in touch with me asap at birju@karmadigi.com?

    thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from CODE t!ps

Subscribe now to keep reading and get access to the full archive.

Continue reading