There is a table with a list of words and checkmarks. If a word is selected, it is added to the array, which is then written to the plist dictionary. I have added and removed only one line. If I select another line, it overwrites the old one. Googled half a day, did not understand what to do, tried to copy the array - did not work. Here is my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; bool isSelected = (cell.accessoryType == UITableViewCellAccessoryCheckmark); NSString *path = [DOCUMENTS stringByAppendingPathComponent:@"userData.plist"]; NSMutableDictionary *data = [NSMutableDictionary dictionaryWithContentsOfFile:path]; NSMutableArray *newData = [[NSMutableArray alloc] init]; if (isSelected) { cell.accessoryType = UITableViewCellAccessoryNone; } else { cell.accessoryType = UITableViewCellAccessoryCheckmark; [newData addObject:cell.textLabel.text]; } [data setObject:newData forKey:@"PersonalQualities"]; NSData *dataToPlist = [NSPropertyListSerialization dataWithPropertyList:data format:NSPropertyListXMLFormat_v1_0 options:0 error:nil]; [dataToPlist writeToFile:path atomically:YES]; }