title: Save data to plist in xcode
body: <p>I understand that you have to retrieve data from plist first, add data, and rewrite the entire contents to the plist file.</p>
  
  <p>But my code here is NOT appending, but refreshing every time I call this method.</p>
  
  <pre><code>- (void) saveDataToPlist {
      // Retrieve path and filename of the plist file
      NSString *myColorsListFile = [self dataFilePath];
  
      NSMutableArray  *innerArray1;
      NSString *error;
  
      UserGivenColorHexString = HexTextField.text;
      NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:100];
  
      if ([[NSFileManager defaultManager] fileExistsAtPath:myColorsListFile]) {
          // File exists
          rootObj = [[NSMutableDictionary alloc] initWithContentsOfFile:myColorsListFile];
  
  
          [innerArray1 addObjectsFromArray:[NSMutableArray arrayWithContentsOfFile:myColorsListFile]];
          [innerArray1 addObject:UserGivenColorName];
  
      } else {
          // Create file
          rootObj = [[NSMutableDictionary alloc] init];
  
          innerArray1 = [NSMutableArray arrayWithObjects: UserGivenColorName, nil];
          [rootObj setObject:innerArray1 forKey:@"ColorName"];
      }
  
      id plist = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&amp;error];
  
      [plist writeToFile:myColorsListFile atomically:YES];
  }
  </code></pre>