jazzedge
11/30/2017 - 12:53 PM

Swift - CloudKit - Predicate to get User

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];