views:

255

answers:

2

Hi everyone, I was wondering if I could select objects based on a predicate with an array... for example

Code: [NSPredicate predicateWithFormat:@"id=%@", arrayOfID];

Will it work? If no, how can I do it?

Best

A: 

Yes, of course you can do it.

Sounds like you need a bit of grounding in Core Data. I found the following tutorial really useful in getting me off the ground with Core Data:

http://iphoneinaction.manning.com/iphone_in_action/2009/08/core-data-part-1-an-introduction.html

pheelicks
You're right... I wasn't able to find a good tuto for the queries!Thanks
ncohen
It doesn't seem to work... I get an error:*** -[NSCFArray longLongValue]: unrecognized selector sent to instance 0x7e2d820*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray longLongValue]: unrecognized selector sent to instance 0x7e2d820'To be clear... id is an int and my array is an array of int!
ncohen
It's not clear from what you've posted what the problem is. If the problem is suffieciently different from the current question, perhaps you could ask a new question?
pheelicks
The error seems to indicate that id is an NSNumber and that hence it tries to send longLongValue to an array because of the `id=%@` predicate. Replacing the = with IN should solve this error because it will send that message to the NSNumbers contained in the array.
Felix
+2  A: 

The correct predicate would be

[NSPredicate predicateWithFormat:@"id IN %@", arrayOfID];

Assuming that arrayOfId contains objects of the same type as id (e.g. NSNumbers or NSStrings).

Felix
Problem solved... thx!
ncohen