每个Time Plist文件都会变得过时

时间:2013-04-03 04:29:27

标签: ios objective-c xcode plist

我使用以下代码访问并将数据附加到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];
    }
}

1 个答案:

答案 0 :(得分:1)

问题是你的plist没有更新任何东西,因为你试图在主bundle中编写plist,在main bundle中你不能写任何东西,所以它可能只采用默认值..

请在此处查看我的回答NSDictionary value replacing instead of adding in Plist