Skip to content

Instantly share code, notes, and snippets.

@jazzedge
Last active November 30, 2017 16:38
Show Gist options
  • Select an option

  • Save jazzedge/86ab3529ce3af292c4c83939a84da3c3 to your computer and use it in GitHub Desktop.

Select an option

Save jazzedge/86ab3529ce3af292c4c83939a84da3c3 to your computer and use it in GitHub Desktop.
Use Predicate - How can an NSPredicate test that a value contains one of two other values?   
See: https://stackoverflow.com/questions/47445895/how-can-an-nspredicate-test-that-a-value-contains-one-of-two-other-values  
I'm trying to write an NSPredicate that expresses: "If uid contains myID OR targetUser"
If you'd wrote it in "code" and not in a predicate, you'd write if ([uid containsCD:myID] || (uid containsCD:targetUser]) not if ([uid containsCD:myID || targetUser]), where containsCD: is the equivalent of contains[cd]. Same logic for the predicate.                                                                                     
Try:
NSPredicate *p3 = [NSPredicate predicateWithFormat:@"(uid contains[cd] %@) OR (uid contains[cd] %@)", myID, targetUser];
Or, without brackets try:
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"uid contains[cd] %@ OR uid contains[cd] %@", myID, targetUser];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment