How to write data in plist file in iphone development

NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:2];NSString *name;

NSDictionary *innerDict;

NSDate *dob;

NSArray *scores;

scores = [NSArray arrayWithObjects:[NSNumber numberWithInt:6],

[NSNumber numberWithFloat:4.6], [NSNumber numberWithLong:6.0000034], nil];

name = @”George Washington”;

dob = [NSDate dateWithString:@”1732-02-17 04:32:00 +0300″];

innerDict = [NSDictionary dictionaryWithObjects:

[NSArray arrayWithObjects: name, dob, scores, nil]

forKeys:[NSArray arrayWithObjects:@”Name”, @”DOB”, @”Scores”]];

[rootObj setObject:innerDict forKey:@”Washington”];

scores = [NSArray arrayWithObjects:[NSNumber numberWithInt:8],
[NSNumber numberWithFloat:4.9],
[NSNumber numberWithLong:9.003433], nil];
name = @”Abraham Lincoln”;
dob = [NSDate dateWithString:@”1809-02-12 13:18:00 +0400″];

innerDict = [NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects: name, dob, scores, nil]
forKeys:[NSArray arrayWithObjects:@”Name”, @”DOB”, @”Scores”]];
[rootObj setObject:innerDict forKey:@”Lincoln”];
id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj
format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

Go through this Link to APPLE’s Documentation  For More Info https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/PropertyLists/CreatePropListProgram/CreatePropListProgram.html

Comments

comments

Leave a Reply

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