objective c - How to filter an object array using another array to define which objects to filter out -


in xcode, have database request online sql database , can stored array or nsdictionary or other type. separately, array of numbers generated in app correspond 1 of columns of database.

i want filter database show objects involved generated array. once filtered, want list results in string. database online server can stored in nsarray or nsdictionary if need be, , other formats don't know about.

the procedure this:

database array: generated array: resultant array after filtering database:

id    |    name          id                        filterednames       | 1a    |   hannah         1a                          hannah 2a    |   john           1b                          steve 3a    |   peter          2b                          zara 1b    |   steve 2b    |   zara 3b    |   kyle 

the resultant array "filterednames" converted string list follows:

namesstring = @"hannah, steve, zara"  

i plan pass namesstring label follows:

label.text=namesstring; 

and label in view shows :

                                hannah, steve, zara  

i pretty need entire procedure.

edit following martin's comment, changed predicate format more appropriate one.

- (nsarray *)filterobjects:(nsarray *)objects withnames:(nsarray *)names {   return [objects filteredarrayusingpredicate:[nspredicate predicatewithformat:@"name in %@", names]]; }  // given 'objects' array server   nsarray *objects = @[                        @{@"id" : @"1a", @"name" : @"hannah"},                        @{@"id" : @"2a", @"name" : @"john"},                        @{@"id" : @"3a", @"name" : @"peter"},                        @{@"id" : @"1b", @"name" : @"steve"},                        @{@"id" : @"2b", @"name" : @"zara"},                        @{@"id" : @"3b", @"name" : @"kyle"}                        ];    nsarray *filteredobjects = [self filterobjects:objects withnames:@[@"hannah", @"john", @"zara"]];   nslog(@"filteredobjects: %@", filteredobjects); // prints them out dictionaries    nsstring *unitednames = [[filteredobjects valueforkeypath:@"@unionofobjects.name"] componentsjoinedbystring:@", "];   nslog(@"unitednames: %@", unitednames); // comma separated array of names 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -