Vinayak Kini
Vinayak Kini

Reputation: 2919

Each Time Plist file gets overwriiten

I have used the following code for accessing and appending data into the plist. But each time the data in the plist is overwritten.

Is there error in the code ?

Please help.

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];
    }
}

Upvotes: 0

Views: 99

Answers (1)

iphonic
iphonic

Reputation: 12717

The problem is your plist is not updating anything, because you are trying to write plist in main bundle, where in main bundle you cannot write anything, so it might be taking the default values only..

See my answer here NSDictionary value replacing instead of adding in Plist

Upvotes: 1

Related Questions