title: Using Casts in a NSPredicate
body: <p>I have a class member "total" which is of type int. I am using "total" as an attribute in my predicate:</p>
  
  <pre><code>[NSPredicate predicateWithFormat: @"total ==%i", [searchText intValue]];
  </code></pre>
  
  <p>This predicate is used to collect matches when a search is executed. The predicate compares the user's search value, stored in iVar <code>searchText</code> , of type text with attribute "total" which is of type int.</p>
  
  <p>I am able to check for equality easily like this:</p>
  
  <pre><code> NSPredicate *filter = [NSPredicate predicateWithFormat: @"total ==%i", [searchText  intValue]];
  </code></pre>
  
  <p>I would now like to make the predicate more robust and work like a text search so if a user types "5" into the search box, the predicate will return 5,52,550,etc.</p>
  
  <p>In other words, I would like to treat "total", which is an attribute, as a string in my predicate filter so I can use <strong>BEGINSWITH or CONTAINS</strong>.</p>
  
  <p>My problem is that the attribute "total" is of type int, not a string so I am stuck.</p>
  
  <p>Here is my intent (pseudo code)</p>
  
  <pre><code>NSPredicate *filter = [NSPredicate predicateWithFormat: @"[total stringValue] BEGINSWITH %@", searchText];
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>  NSPredicate *filter = [NSPredicate predicateWithFormat: @"CAST(total, 'NSString' ) BEGINSWITH %@", searchText];
  </code></pre>
  
  <p>How can I do this without creating a string type in my class?</p>
  
  <p>Thanks!</p>