views:

44

answers:

1

Here is how I can get the value:

NSString *path =  [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *tempArray = [dict valueForKey:@"2"];
NSString *myTarget = [tempArray objectAtIndex:0];

the "myTarget" is something I want to replace with, how can I replace it with @"newString" and write to plist? thz u.

+2  A: 

Do this:

NSString *path =  [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
NSData * data = [NSData dataWithContentsOfFile:path];
NSMutableDictionary * dict = (NSMutableDictionary *)[NSPropertyListSerialization
                                    propertyListFromData:data
                                    mutabilityOption:NSPropertyListMutableContainersAndLeaves
                                    format:NULL
                                    errorDescription:NULL];
NSMutableArray *tempArray = [dict valueForKey:@"2"];
NSString *myTarget = [tempArray objectAtIndex:0];
[parents replaceObjectAtIndex:0 withObject:newString];
[currentBox writeToFile:[path stringByExpandingTildeInPath] atomically:YES];
Mo