title: Removing cells from UITableView in iOS, along with an NSMutableArray - error
body: <p>I am making a test to see if I can store questions and answers, and I am using an UITableView. When I come to delete things from the table view, I use this code:</p>
  
  <pre><code> -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  if (editingStyle == UITableViewCellEditingStyleDelete) {
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];{
  
      }
      NSMutableArray *userQuestions = [defaults objectForKey:@"questionsArray"];
      NSMutableArray *userAnswers = [defaults objectForKey:@"answersArray"];
  
      [userQuestions removeObjectAtIndex:indexPath.row];
      [userAnswers removeObjectAtIndex:indexPath.row];
  
      [defaults setObject:userQuestions forKey:@"questionsArray"];
      [defaults setObject:userAnswers forKey:@"answersArray"];
  
      [defaults synchronize];
  
      [self.tableView beginUpdates];
      [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
      [self.tableView endUpdates];
      }
  }
  </code></pre>
  
  <p>When I delete a cell, the app crashes with this report:
  <code>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
  </code></p>
  
  <p>At a first glance, I recognised that the NSMutableArray had been passed immutable by the NSUserDefaults. I tried to see if I could put the array into a placeholder array but I had no luck. Does anyone know how I could delete rows from the UITableView correctly?</p>
  
  <p><strong>Answered</strong> </p>
  
  <p>Thank you everyone that commented, I now have replaced these lines:</p>
  
  <p><code>NSMutableArray *userQuestions = [defaults objectForKey:@"questionsArray"];
  NSMutableArray *userAnswers = [defaults objectForKey:@"answersArray"];</code></p>
  
  <p>with these lines:</p>
  
  <p><code>NSMutableArray *userQuestions = [[defaults objectForKey:@"questionsArray"] mutableCopy];
  NSMutableArray *userAnswers = [[defaults objectForKey:@"questionsArray"] mutableCopy];</code></p>
  
  <p>It works perfectly now that 'userQuestions' and 'userAnswers' are being declared to a mutable copy of an originally immutable array - I understand now. Thanks again!</p>