[Programming] How To – Write/Read .plist files in an iPhone Application


I came across a very good post at iPhone Dev SDK, and it is a very good one 🙂

– (void)readPlist

{

NSString *filePath = @”/System/Library/CoreServices/SystemVersion.plist”;

NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

NSString *value; value = [plistDict objectForKey:@”ProductVersion”];

/* You could now call the string “value” from somewhere to return the value of the string in the .plist specified, for the specified key. */

}

– (void)writeToPlist

{

NSString *filePath = @”/System/Library/CoreServices/SystemVersion.plist”;

NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

[plistDict setValue:@”1.1.1″ forKey:@”ProductVersion”];

[plistDict writeToFile:filePath atomically: YES];

/* This would change the firmware version in the plist to 1.1.1 by initing the NSDictionary with the plist, then changing the value of the string in the key “ProductVersion” to what you specified */

}

Advertisements