Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

teguh123

macrumors member
Original poster
Mar 22, 2011
62
0
With into one?

Code:
NSPredicate * thePredicate1= [NSPredicate predicateWithFormat: @"Title CONTAINS[cd] %@", searchTerm];
NSPredicate * thePredicate2= [NSPredicate predicateWithFormat: @"Street CONTAINS[cd] %@", searchTerm];
NSPredicate * thePredicate3= [NSPredicate predicateWithFormat: @"Building CONTAINS[cd] %@", searchTerm];
NSPredicate * thePredicate4= [NSPredicate predicateWithFormat: @"any Districts CONTAINS[cd] %@", searchTerm];

I want thePredicate= Predicate1 or predicate2 or predicate 3 or something like that.
 
Last edited by a moderator:
I've read the NSPredicate documentation and couldn't wrap my head around it all the way. Simple predicates I can understand, but now how do I create a predicate for the following situation:

I have an array of Foo objects. In the Foo class, one of the iVars is an NSMutableArray of Bar objects. I need to filter the array of Foo objects to get those that have a particular Bar object in its array. How?

Also, is it any easier (or possible) to find multiple Bar objects at once, or to combine several predicates that each search for a particular Bar?
 
Awesome, how else I can ask this more quickly by search engine. Searching for combining NSPredicate don't see any result.

Hmm.... How do we know what soft of subclasses of NSPredicate?

Start at the class reference for a specific class, such as NSPredicate:
http://developer.apple.com/library/.../NSPredicate_Class/Reference/NSPredicate.html

You can use search engine terms: ClassNameHere class reference
where ClassNameHere is the specific class name you're looking for. However you get there, start at the class reference doc.

Once in the class reference doc, look at the column on the left, where it says COMPANION GUIDE, under which is "Predicate Programming Guide". Click that:
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/Predicates/predicates.html

Now look on the left again, maybe scrolling it down so you can see the classes under the OBJECTIVE-C REFERENCE heading:
NSComparisonPredicate
NSCompoundPredicate
NSExpression
NSPredicate

Those classes are the predicate classes. Click each one to show its class reference doc.


This is the general strategy:
1. Look up a particular class reference doc (example: NSPredicate)
2. Look on the left for COMPANION GUIDE links, there may be more than one (example: Predicate Programming Guide).
3. After reading the companion guide, look on its left for the relevant classes, usually listed under OBJECTIVE-C REFERENCE, which will be class reference docs.
4. Be sure to look for RELATED DOCUMENTS (again on the left).

This is the general structure of all Cocoa documents. The class reference doc has links to companion guides on the left, and companion guides have links to class reference docs and related documents.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.