NSMutableArray writeToFile: atomically always returns NO to the device, but works fine on the simulator

I have a plist file with a root of type Array in resources in an xcode project. By clicking on the button, I need to access this plist and find if plist already contains a specific element, if not write a new element (NSString) to plist.

I do it 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 always seems to return NO.

I even tried with NSArchiver, even this seems to return NO as return value to me

Can someone tell me what I'm doing wrong.

Hi,

Sayed Yusuf

+1
source share
2 answers

, plist Resources. plist Documents .

+6

, , :

iPhone?

.

+1

All Articles