0
NSMutableArray *arrayOfPredicates=[[NSMutableArray alloc]init];
[self.attendeeListSet enumerateObjectsUsingBlock:^(id obj, BOOL *stop){
    NSString *userId=[obj userId];
    [arrayOfPredicates addObject:[NSPredicate predicateWithFormat:@"userID == %@",userId]];
}];
NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:arrayOfPredicates];
[request setPredicate:compoundPredicate];

I am setting this compound predicate for multiple userIds in an array and i need to get the Users from those User ids using OR.

The above is not working but when I'm hardcoding using

 NSPredicate *predicate1=[NSPredicate predicateWithFormat:@"(userID like[cd] %@) 
                            OR (userID like[cd] %@)",@"sheetal2", @"sheetal3"];  
[arrayOfPredicates addObject:predicate1];

Now this is working..Can anyboady tell whats the problem with my code..

Thanks

sheetal
  • 3,014
  • 2
  • 31
  • 45
  • This may sound silly, in the first one you are using userID and in the other you are suing eventID? – Anupdas Jun 12 '13 at 06:12
  • @Anupdas leave the IDs...what i ma saying is its not working...i just copy pasted..i have Editted – sheetal Jun 12 '13 at 06:30
  • 1
    When you are posting question, leave no room for guess work. Even now your above query is case sensitive and second one is case insensitive? And also log `arrayOfPredicates` to see their content. – Anupdas Jun 12 '13 at 06:34

1 Answers1

1

In your first code the predicate uses ==. In the second code the predicate uses LIKE[cd]. Because the userID is an NSString, using LIKE is generally a better way to tell the predicate to compare the values, but the real difference is that the second approach is case and diacritic insensitive and the first approach requires an exact match.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Can you please check the comments of MartinR on this [answer](http://stackoverflow.com/a/16358617/767730). I think using of `LIKE` is not always the best. – Anupdas Jun 12 '13 at 06:49
  • 2
    Thanks @Anupdas, I've improved the answer and I never thought of doing '==[cd]' before, good information. – Wain Jun 12 '13 at 07:05
  • But i dont know why when i was hardcoding == was working as well – sheetal Jun 12 '13 at 09:23