我已经使用以下代码来访问数据并将其附加到 plist 中。但是每次plist中的数据都会被覆盖。
代码有错误吗?
请帮忙。
NSString* plistPath = nil;
NSFileManager* manager = [NSFileManager defaultManager];
if ((plistPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"stores.plist"]))
{
if ([manager isWritableFileAtPath:plistPath])
{
NSArray * infoArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
NSMutableArray * newArray = [infoArray mutableCopy];
NSMutableDictionary *infoDict = [[NSMutableDictionary alloc]init];
[infoDict setObject:@"a object" forKey:@"Lname"];
[infoDict setObject:@"3s3z32 object" forKey:@"Fname"];
[newArray addObject:infoDict];
[newArray writeToFile:plistPath atomically:TRUE];
[manager setAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] ofItemAtPath:[[NSBundle mainBundle] bundlePath] error:nil];
}
}