objective c - Obj-c - How can I check if NSString contains one OR the other? -
i want check if nsstring 'name' contains "brittany" or "bob", following code doesn't seem trick?
viewcontroller.m
nspredicate *p = [nspredicate predicatewithformat:@"name contains[cd] %@ or name contains[cd] %@", @"brittany", @"bob"]; nsarray *filtered = [self.messages filteredarrayusingpredicate:p];
any idea should instead? can't seem syntax right. issue 'filtered' not returning arrays in string name containing "bob", ones in name contains "brittany".
here self.messages contains:
messages data ( { body = "hi"; endswaptime = "<null>"; "first name" = brittany; name = brittany; nid = 1803; "node_title" = "re:"; }, { body = "it brittany"; endswaptime = "<null>"; "first name" = brittany; name = brittany; nid = 1804; "node_title" = "re:"; }, { body = "hellooo :)\n"; endswaptime = "<null>"; "first name" = bob; name = "bob"; nid = 1805; "node_title" = "re:"; } )
perhaps splitting predicate 2 separate predicates , combining nscompoundpredicate
help?
nspredicate *p1 = [nspredicate predicatewithformat:@"name contains[cd] %@", @"brittany"]; nspredicate *p2 = [nspredicate predicatewithformat:@"name contains[cd] %@", @"bob"]; nscompoundpredicate *p = [nscompoundpredicate orpredicatewithsubpredicates:@[p1, p2]]; nsarray *filtered = [self.messages filteredarrayusingpredicate:p];
Comments
Post a Comment