0
- (void)filterViaCategories:(NSArray *)array   {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(todo_category_id == %@)" argumentArray:array]; 
}

but when I have used:

po predicate

Result is:

todo_category_id == 41123..

It just using 41123 from zero index element of array

i want all categories from data base for all id present in array not the only object at index zero: (todo_category_id == 41123, 41234, 33455) etc.

How can I do this?

Random
  • 431
  • 8
  • 20
Umair Suraj
  • 480
  • 11
  • 22

1 Answers1

1

Then you should not be using predicateWithFormat:argumentArray: and you need to change your format.

You want something like:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"todo_category_id IN %@", array]; 
Wain
  • 118,658
  • 15
  • 128
  • 151
  • but i causes me an error like: [__NSCFNumber countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance – Umair Suraj Feb 11 '14 at 14:02
  • my array has NSNumber elements inside..can i change them to string values of "ids".? – Umair Suraj Feb 11 '14 at 14:04
  • `todo_category_id` is a string attribute? But the array contains only numbers? – Wain Feb 11 '14 at 14:06
  • Then it looks like you didn't actually send an array to the method, you just sent an individual `NSNumber` instance... – Wain Feb 11 '14 at 14:14
  • I have checked inside array..it has count of 3 and values thats i have printed at its index are 1254,8765,9853 – Umair Suraj Feb 11 '14 at 14:18
  • What is the stack trace then as you are definitely using a number when the code expects an array. – Wain Feb 11 '14 at 14:26
  • How can i find stack trace? – Umair Suraj Feb 11 '14 at 14:27
  • Add an all exception breakpoint in Xcode so the debug session stops when any exception is found – Wain Feb 11 '14 at 14:30
  • debugger stops at main.m and causing this error inside console [__NSCFNumber countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xb0000000000a0a33 – Umair Suraj Feb 11 '14 at 14:35
  • Did you add the breakpoint? Try pressing continue to get a stack trace in the console. Or look at the left of the screen for a stack trace. – Wain Feb 11 '14 at 14:36