Hello i have a maybe easy question but i cant handle it yet.
- I have a Modelclass 'Location' which holds an Array with Category ID's (12, 23, 56).
- Then i have an Array with all available Category ID's (1,2,3,4,5,6,7,...)
- All this Categories have an ID are shown in a TableView and are able to select or not.
- I show a punch of Markers on a MapView (Annotation Class is Location) which should be shown based on the selection of the filters in the mentioned Filter TableView.
I need to implement a "Filter by Category" function which removes all markers and add them again but just based on the selection in the list.
So i need to compare the array with the filter-id's in the Location Model with the Array with all the Filter-ID's in the TableView. i used the following function for this:
for (Location *currLocation in arrListOfLocationsNearby) {
for (NSString *currKatId in currLocation.arrKatIds) {
NSInteger intCurrKatId = [currKatId integerValue];
NSLog(@"Current KatId %@ id: %d \n", currLocation.strAdr, intCurrKatId);
for (Filter *currFilter in [SDM getSharedDataManager].arrListOfFilterOptions) {
if (currFilter.isSelected) {
NSInteger intCurrFilterId = [currFilter.strAtt_id intValue];
NSLog(@"Current Filter %@ id: %d \n", currFilter.strAtt_text, intCurrFilterId);
if ([currKatId intValue] == [currFilter.strAtt_id intValue]) {
currLocation.isVisible = YES;
}else {
currLocation.isVisible = NO;
}
}
}
} }
I know this will be the most ineffective way to loop through everything. I want to use somehow NSPredicate for this but i never used them before and i can't find examples for my problem.
Any Hints from you guys?
regards m.