title: NSPredicate 101: Using NSPredicate with a NSMutableArray of custom objects
body: <p>This is a pretty basic question here, and even though I think understand the basics of NSPredicate, I'm still a little stumped as to why I'm getting an error here (searchText is a pointer to a NSString object that's being passed into the method). </p>
  
  <pre><code>NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[cd] %@", searchText];
  _searchResults = [_personArray filteredArrayUsingPredicate:predicate];
  </code></pre>
  
  <p>I have a NSMutableArray of custom objects (e.g., Person objects), which have a name property. All I'm trying to do is use a NSPredicate to filter potential matches when the user begins typing in a UISearchBar. The IB component is straightforward enough and appears to function just fine. When I attempt to search and begin filtering however, the basic application crashes with the following error:</p>
  
  <p><code>'NSInvalidArgumentException', reason: '-[xPerson isEqualToString:]: unrecognized selector sent to instance 0x8043340'</code></p>
  
  <p>My understanding is the predicate will be passed to each object in the NSMutableArray, with the SELF keyword in the predicate referring to the respective object (and which, I believe, isn't even really necessary in this case), and the .name being able to use the synthesized property on the custom object. The error seems to suggest the -isEqualToString: call is being called on the custom object and not the object's property.</p>
  
  <p>Any suggestions on what I'm doing wrong would be tremendously appreciated.</p>