title: Searching through NSMutableArray of objects with NSPredicate
body: <p><strong>The question is solved, here is how I fixed it for future reference for noobs like me</strong>
  I needed to remove the white-spaces:
  <code>        ship.countryOfbuild =  [[elements objectAtIndex:0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];</code></p>
  <p>And I had to change the predicate like this: <code>    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@&quot;(countryOfBuild contains[cd] %@) OR (shipBuilder contains[cd] %@) OR (name contains[cd] %@) OR (owner contains[cd] %@)&quot;,searchText, searchText, searchText, searchText];</code></p>
  <p><em>Original question</em></p>
  <p>I'm using <a href="http://www.appcoda.com/how-to-add-search-bar-uitableview/" rel="noreferrer">this tutorial</a> to add a search bar to my project. I got the tableview all working, but the search function is crashing the app. The way I search now is:</p>
  <pre><code>-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
  {
  NSPredicate *resultPredicate = [NSPredicate
                                  predicateWithFormat:@&quot;SELF contains[cd] %@&quot;,
                                  searchText];
  
  searchResults = [searchContent filteredArrayUsingPredicate:resultPredicate];
  }
  </code></pre>
  <p>The <code>searchContent</code>is a mutable array read from a .csv-file like this:</p>
  <pre><code>- (void)viewDidLoad
  {
  [super viewDidLoad];
  NSString* pathToFile = [[NSBundle mainBundle] pathForResource:@&quot;ships&quot; ofType: @&quot;csv&quot;];
  
  NSString *file = [[NSString alloc] initWithContentsOfFile:pathToFile encoding:  NSUTF8StringEncoding error:NULL];
  
  NSArray *allLines = [file componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
  
  
  searchContent           = [[NSMutableArray alloc] init];
  
  
  for (NSString* line in allLines) {
      NSArray *elements = [line componentsSeparatedByString:@&quot;;&quot;];
      
      CargoShips* ship = [[CargoShips alloc]init];
      ship.countryOfbuild =  [elements objectAtIndex:0];
      ship.shipBuilder =     [elements objectAtIndex:1];
      ship.hullHashtag =     [elements objectAtIndex:2];
      ship.name =            [elements objectAtIndex:3];
      ship.owner =           [elements objectAtIndex:4];
      ship.shipOperator =    [elements objectAtIndex:5];
      ship.shipDelivery =    [elements objectAtIndex:6];
      ship.shipFlag =        [elements objectAtIndex:7];
      ship.shipClass =       [elements objectAtIndex:8];
      ship.powerPlant =      [elements objectAtIndex:9];
      ship.HP =              [elements objectAtIndex:10];
      ship.speed =           [elements objectAtIndex:11];
      ship.cargoSystem =     [elements objectAtIndex:12];
      ship.numberOfTanks =   [elements objectAtIndex:13];
      ship.size =            [elements objectAtIndex:14];
      [self.searchContent   addObject:ship];
  }
  </code></pre>
  <p>I would like the search to search through all 15 pieces of the object (name, size, shipclass etc)</p>
  <p>Currently, this crashes with the error:</p>
  <p><code>*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use in/contains operator with collection &lt;CargoShips: 0x714e1b0&gt; (not a collection)'</code></p>
  <p>CargoShips is my NSObject class.</p>
  <p>How do I fix the NSPredicate to search through an <code>NSMutableArray</code>with objects without crashing?</p>
  <p>Here is the full code if that makes stuff easier <a href="http://pastebin.com/sw12GwHK" rel="noreferrer">http://pastebin.com/sw12GwHK</a></p>