My problem is when I read content of plist file in an NSMutableArray always return null
NSString *resourceDocPath = [[NSString alloc] initWithString:[[NSBundle mainBundle]bundlePath]] ;
// Create the new dictionary that will be inserted into the plist.
NSMutableDictionary *nameDictionary = [NSMutableDictionary dictionary];
[nameDictionary setValue:@"walid" forKey:@"id"];
[nameDictionary setValue:@"555 W 1st St" forKey:@"lien"];
NSString *r = [NSString stringWithFormat:@"%@/download.plist", resourceDocPath];
NSLog(@"%@",r);
// Open the plist from the filesystem.
NSMutableArray *plist = [NSMutableArray arrayWithContentsOfFile:r];
NSLog(@"%@",plist);
if (plist == NULL)
{
plist = [NSMutableArray array];
}
[plist addObject:nameDictionary];
NSLog(@"%@",plist);
[plist writeToFile:r atomically:YES];
when I look in the plist file I found the data that I insert only one
can you help me please?
You’re trying to access the application bundle rather than the documents directory, which can be accessed via
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];. The bundle cannot be modified, so the created array is never saved, hence why it is never loaded.NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];