Read Write value from plist file in iphone

Here is the method how to read or write in plist file in iphone development

-(void)writeToPlist:(NSString *)User_Id
{
    NSString* path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    NSMutableDictionary *UserData = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
    [UserData setObject:User_Id forKey:@"CustomerId"];
    [UserData writeToFile:path atomically:YES];
    [UserData release];
}
-(NSString *)ReadFromPlist
{
    NSString* path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    NSMutableDictionary *UserData = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
    return [UserData valueForKey:@"CustomerId"];
    [UserData release];
}

2 comments:

Hi I have written a PlistManager file that makes using plist files in swift easy: http://rebeloper.com/read-write-plist-file-swift/ Full step by step tutorial with lots of images.

Post a Comment

Powered by Blogger.
Twitter Delicious Facebook Digg Stumbleupon Favorites More