title: Append items to an existing key in NSDictionary saved in a plist
body: <p>How can I append values to an existing key in NSDictionary from a plist?</p>
  
  <p>What I have is basically a plist saved in disc with a few keys and values, the keys are the names of some students with one initial value. What I’m trying to do that doesn't work is to append more items to existing keys/Students by reading the plist, adding it to a temporary NSDictionary, appending a temporary array to an existing key in the plist but when I save the plist back it doesn’t work, it only saves the last two items and basically deletes the initial value for that key. </p>
  
  <p>Here is the code that I’m using…</p>
  
  <pre><code>- (IBAction)testing:(id)sender
  {
      NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsPath = [dirPaths objectAtIndex:0];
      NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"studentsRecords.plist"];
  
      BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
  
      if(fileExists)
      {
          NSMutableDictionary *dictionaryRecords = [[NSMutableDictionary alloc]initWithContentsOfFile:fullPath];
          NSLog(@"Items for Nathan: %@",[dictionaryRecords objectForKey:@"Nathan"]);// here the output is, Items for Nathan: Ruler
          // which make sense since I only had one initial record for Nathan in my plist,
  
          // Here, I want to add two more items to the key Nathan by appending an arry to
          // NSMutableDictionary (dictionaryRecords) but it doesnt work
          NSArray *tempArray = @[@"NoteBook", @"Pencil"];
          [dictionaryRecords setObject:tempArray forKey:@"Nathan"];
  
          [dictionaryRecords writeToFile:fullPath atomically:YES];
          // when I check the plist after saving this, I only see the last two values, NoteBook and Pencil
          // instead of the three that I'm expecting, Ruler, NoteBook and Pencil
      }
  
  }
  </code></pre>
  
  <p>What am I missing here? </p>
  
  <p>Thanks a lot in advance.</p>