I have a plist file with root of type Array in the resources in the xcode project. On a button click i need to access this plist and find if the plist already contains the particular item if not write the new item(NSString) to the plist.
I am doing this as follows,
NSMutableArray *array = nil;
NSDictionary *dictionary = nil;
path = [[NSBundle mainBundle] pathForResource:@"MyPlistName" ofType:@"plist"];
array = [[NSMutableArray alloc] initWithContentsOfFile:path];
dictionary = [self.dictionary objectForKey:@"tag"];
if(![array containsObject:dictionary])
{
[array addObject:dictionary];
if(![array writeToFile:path atomically:YES])
{
NSLog(@".plist writing was unsucessfull");
}
}
This works for me on the simulator but when i run it on the device the writeToFile:atomically method seems to return NO always.
i even tried with NSArchiver even that seems to return me NO as the return value
Can any one tell what am i doing wrong..
Regards,
Syed Yusuf