title: Why am I getting : "mutating method sent to immutable object" when trying remove from MutableArray?
body: <p>I can't figure out why I am getting the 'mutating method sent to immutable object' in this piece of code. The array must be immutable somehow but I don't know why.</p>
  
  <p>Interface:</p>
  
  <pre><code>    @interface SectionsViewController : UIViewController&lt;UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate&gt; {
  
      UITableView *table;
      UISearchBar *search;
      NSMutableDictionary *names;
      NSMutableArray *keys;
  
  }
  @property (nonatomic, retain) IBOutlet UITableView *table;
  @property (nonatomic, retain) IBOutlet UISearchBar *search;
  @property (nonatomic, retain) NSDictionary *allNames;
  @property (nonatomic, retain) NSMutableDictionary *names;
  @property (nonatomic, retain) NSMutableArray *keys;
  
  -(void) resetSearch;
  -(void) handleSearchForTerm:(NSString *)searchTerm;
  
  @end
  </code></pre>
  
  <p>Notice that names is a MutableDictionary. </p>
  
  <p>The following line is throwing the exception</p>
  
  <pre><code>[array removeObjectsInArray:toRemove];
  </code></pre>
  
  <p>Here the method in full context:</p>
  
  <pre><code>-(void)handleSearchForTerm:(NSString *)searchTerm
  {
      NSMutableArray *sectionsToRemove = [[NSMutableArray alloc] init];
      for(NSString *key in self.keys)
      {
          NSMutableArray *array = [names valueForKey:key];
          NSMutableArray *toRemove = [[NSMutableArray alloc] init];
  
          for(NSString *name in array)
          {
              if([name rangeOfString:searchTerm
                             options:NSCaseInsensitiveSearch].location == NSNotFound)
                  [toRemove addObject:name];
          }
          if([array count] == [toRemove count])
              [sectionsToRemove addObject:key];
  
          [array removeObjectsInArray:toRemove];
          [toRemove release];
      }
      [self.keys removeObjectsInArray:sectionsToRemove];
      [sectionsToRemove release];
      [table reloadData];
  }
  </code></pre>
  
  <p>I am assigning array from the result of this [names valueForKey:key];
  array is of type 'MutableArray' What am I missing?</p>
  
  <p>Thanks!</p>