title: Unable to write to plist file
body: <p>I've found several questions here on the site with people who have a similar problem, but I'm still not able to resolve mine. Here's the thing:</p>
  
  <p>I'm making an iOS app that contains two plist files. When the user opens the app for the first time, the application takes care of moving these two files to the Documents directory. I know this code works, since I'm subsequently able to read from each of the files in the Documents directory path. However, I'm not able to write to any of them for apparent unknown reasons. Here is the code I use to write to the first plist file:</p>
  
  <pre><code>+ (void)insertNewElementWith:(NSArray *)objects andKeys:(NSArray *)keys {
      NSString *filePath = [self returnPathForFirstPlistFile];
      NSMutableDictionary *contentOfFirstPlistFile = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
      NSDictionary *dictionary = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
      [contentOfFirstPlistFile setObject:dictionary forKey:[NSNumber numberWithInt:[contentOfFirstPlistFile count]]];
      [contentOfFirstPlistFile writeToFile:filePath atomically:YES];
      [dictionary release];
  }
  </code></pre>
  
  <p><code>returnPathForFirstPlistFile</code> <strong>does</strong> work, since <code>contentOfFirstPlistFile</code> contains <code>{ }</code> rather than <code>null</code>. Can anyone explain to me, though, why it keeps returning <code>{ }</code>, even though the above method has been called several times.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Here is the code I use to place the files in the Documents directory. <code>placePlistsInDocumentsDirectory</code> is <strong>only</strong> called when the user logs in through the app, so this only happens once.</p>
  
  <pre><code>+ (NSString *)returnPathForFirstPlistFile {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"First.plist"];
  
      return filePath;
  }
  
  + (NSString *)returnPathForSecondPlistFile {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSLog(@"%@", [paths objectAtIndex:0]);
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Second.plist"];
  
      return filePath;
  }
  
  + (void)placePlistsInDocumentsDirectory {
      NSFileManager *fileManager = [NSFileManager defaultManager];
      NSString *firstPlistPath = [self returnPathForFirstPlistFile];
      NSString *secondPlistPath = [self returnPathForSecondPlistFile];
  
      if (![fileManager fileExistsAtPath:firstPlistPath]) {
          NSError *error;
          NSString *bundle = [[NSBundle mainBundle] pathForResource:@"First" ofType:@"plist"];
          [fileManager copyItemAtPath:bundle toPath:firstPlistPath error:&amp;error];
      }
  
      if (![fileManager fileExistsAtPath:secondPlistPath]) {
          NSError *error;
          NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Second" ofType:@"plist"];
          [fileManager copyItemAtPath:bundle toPath:secondPlistPath error:&amp;error];
      }
  }
  </code></pre>