views:

207

answers:

3

Hi all,

I have an Cocoa Core-Date Application. I added a search field and bound it. Now, I have tried to add some predicates but failed! Here are my two questions:

First, the predicate should filter NSNumbers but I cannot build a working predicate. My try:

keyPath == [NSNumber numberWithInteger:[$value integerValue]]

(keyPath represents a NSNumber which stores an integer.)

Second, I want to have a predicate which searches in two attributes. The first attribute is firstName and the other lastName. So, if the user types "John Appleseed" he gets an result but with my tries I only get firstName or lastName.

Thanks for your help, if there are any questions ask them. I dont know if I described my problem detailed enough ;-)

Dennis

A: 
  1. Don't construct NSNumber in predicate, compare to $value directly.
  2. Predicates can be combined to make a complex predicate. You can either build it in code or use logic operators (or, ||, and , &&) to build a complex predicate with format.

Apple's documentation has enough samples of predicates using, read it: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/Reference/NSPredicate.html

Gobra
+1  A: 

(1) keypath==$value

(2) firstName==$firstNameVar && lastName==$lastNameVar

TechZen
A: 

Ok sorry i have forgotten one important Detail, sorry about that. The Predicate is a Binding of an NSSearchField.

So i dont know how i am able to use two different variables. Or is it possible to define a Predicate in Code and bind it to the SearchField?

Dennis S.
Just as a reminder you can always edit your question in order to clarify within context.
RyanJM