ios - Filter NSMutableArray on the base of filtering another NSMutableArray -


i have 3 nsmutablearrays of identical size. "linked" means corresponding index have related each other.

tabledata = [nsmutablearray arraywithobjects:@"egg benedict", @"mushroom risotto", @"full breakfast", nil]  thumbnails = [nsmutablearray arraywithobjects:@"egg_benedict.jpg", @"mushroom_risotto.jpg", @"full_breakfast.jpg",nil]  preptime = [nsmutablearray arraywithobjects:@"10min", @"15min", @"8min",nil] 

this comes tutorial i'm playing on.

i'm filtering tabledata array this:

nspredicate *resultpredicate = [nspredicate                                     predicatewithformat:@"self contains[cd] %@",                                     searchtext];  searchresultsdata = [[tabledata filteredarrayusingpredicate:resultpredicate] mutablecopy]; 

where searchtext string containing filter (for example "egg"). works great, mean have correct filtering. (searchresultsdata nsmutablearray) need filter other 2 nsmutablearrays on basis of result got nspredicate above.

so created other 2 nsmutablearrays called "searchresultthumbnails" , "searchresultpreptime". i'm expecting this: if filter using word "egg" want first element containing "egg" "tabledata" array (in case 1 element) , correspondent element @ index in thumbnails , preptime arrays.

so after filtering "egg" result should be:

searchresultdata = "egg" searchresultthumbnails = "egg_benedict.jpg" searchresultpreptime = "10min" 

thank help.

believing "they "linked" means corresponding index have related each other." situation

nspredicate *resultpredicate = [nspredicate                                 predicatewithformat:@"self contains[cd] %@",                                 searchtext];  searchresultsdata = [[tabledata filteredarrayusingpredicate:resultpredicate] mutablecopy]; nsstring *searchedtext = [searchresultsdata objectatindex:0]; nsinteger index = [tabledata indexofobject:searchedtext]; //if searchedtext = "egg" nsstring *thumb = [thumbnails objectatindex:index]; nsstring *prep= [preptime objectatindex:index]; 

but not better way this.

you got couple of options can use custom class might have properties item, thumbnail, preptime.

you can use array of dictionaries similar following format,

 array = (           {              searchresultdata = "egg"              searchresultthumbnails = "egg_benedict.jpg"              searchresultpreptime = "10min"           }           {              searchresultdata = "someitem"              searchresultthumbnails = "some.jpg"              searchresultpreptime = "10min"           }         ) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -