Search code examples
iosplistnsmutabledictionarywritetofile

iOS - NSMutableDictionary writeToFile returns YES but plist is not modified


I am trying to save data in a NSMutableDictionary to a plist. Plist is already in the Resources folder. When I am trying to save the data to the plist using following code it returns YES which means data was successfully saved. But when I check the file data is not saved to it.

    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
    NSString *documentsDirectory = [paths objectAtIndex:0]; //2
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"userInfo.plist"]; //3
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if (![fileManager fileExistsAtPath: path]){ //4    {
        NSString *bundle = [[NSBundle mainBundle] pathForResource:@"userInfo" ofType:@"plist"]; //5
        [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
    }

    BOOL b = [self.userInfoArray writeToFile:path atomically: YES];
    NSLog(@"status %i ", b);

Anyone have solution of this ?


Solution

  • I think I was looking at the wrong file. Plist file in the Xcode does not change after saving the data. Instead, plist in the simulator is changing.