ios - Objective-C: NSPredicate Check Two Arrays -


right now, have working app (similar whatsapp) users can live search using nstextfield add users group chat. using nspredicate, search through array (searchablecontacts) find available contacts on app, , matches output uitableview, so:

- (void)textfielddidchange :(uitextfield *)thetextfield {  [filteredarray removeallobjects];  nsmutablearray *partpredicates = [nsmutablearray arraywithcapacity:2];  nspredicate *currentpartpredicate1 = [nspredicate predicatewithformat:@"firstname contains[cd] %@", self.searchfield.text]; nspredicate *currentpartpredicate2 = [nspredicate predicatewithformat:@"lastname contains[cd] %@", self.searchfield.text];  [partpredicates addobject:currentpartpredicate1]; [partpredicates addobject:currentpartpredicate2];  nspredicate *fullpredicate = [nscompoundpredicate orpredicatewithsubpredicates:partpredicates];  filteredarray = [[self.searchablecontacts filteredarrayusingpredicate:fullpredicate] mutablecopy];  [self.searchablemembers reloaddata];  } 

on resulting tableview, users able select users add group. now, have 'addedcontacts' array.

when user goes textfield search more users add group, how can alter nspredicate include available contacts (from searchablecontacts) not in group (addedcontacts)?

you can simplify code have building predicate this:

nspredicate *predicate = [nspredicate predicatewithformat:@"firstname contains[cd] %@ or lastname contains[cd] %@", self.searchfield.text,  self.searchfield.text]; 

you can adjust exclude items in addedcontacts using this:

nspredicate *predicate = [nspredicate predicatewithformat:@"(not self in %@) , (firstname contains[cd] %@ or lastname contains[cd] %@)", self.addedcontacts, self.searchfield.text, self.searchfield.text]; 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -