以下是我如何获得价值:
NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *tempArray = [dict valueForKey:@"2"];
NSString *myTarget = [tempArray objectAtIndex:0];
“myTarget”是我要替换的东西,如何用@“newString”替换它并写入plist?你好。
答案 0 :(得分:3)
这样做:
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];
[tempArray replaceObjectAtIndex:0 withObject:newString];
[dict writeToFile:[path stringByExpandingTildeInPath] atomically:YES];