title: iPhone read/write .plist file
body: <p>I'm making a application where I need to store some information the user have provided. I try to use a .plist file to store the information, I found this:</p>
  
  <pre><code>NSString *filePath = @"/Users/Denis/Documents/Xcode/iPhone/MLBB/data.plist";
  NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
  [plistDict setValue:@"Man" forKey:@"Gender"];
  [plistDict writeToFile:filePath atomically: YES];
  </code></pre>
  
  <p>The problem is that the application will only work as long as I'm testing it in the iPhone simulator. I've tried this <a href="https://stackoverflow.com/questions/1680367/changing-data-in-a-plist">Changing Data in a Plist</a> but without luck. I have also read something about that I need to add it to my bundle, but how?</p>
  
  <p>New code:</p>
  
  <pre><code>- (IBAction)segmentControlChanged{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *plistLocation = [documentsDirectory stringByAppendingPathComponent:@"data.plist"];
  NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistLocation];
  
  if (Gender.selectedSegmentIndex == 0) {
      [plistDict setObject:@"Man" forKey:@"Gender"];
      [plistDict writeToFile:plistLocation atomically: YES];
  }
  else
  {
      [plistDict setObject:@"Women" forKey:@"Gender"];
      [plistDict writeToFile:plistLocation atomically: YES];
  }
  }
  </code></pre>