gro*_*ald 4 iphone objective-c nspredicate
你好,我有一个简单的问题但我无法处理它.
我需要实现一个"按类别筛选"功能,该功能会删除所有标记并再次添加它们,但这只是基于列表中的选择.
所以我需要将数组与位置模型中的filter-id进行比较,并将数组与TableView中的所有Filter-ID进行比较.我使用了以下功能:
for (Location *currLocation in arrListOfLocationsNearby) {
Run Code Online (Sandbox Code Playgroud)
for(NSrtring*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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
}}
我知道这将是循环通过一切的最无效的方式.我想以某种方式使用NSPredicate,但我以前从未使用它们,我找不到我的问题的例子.
你们有什么提示吗?
关于m.
那么每个"Location"对象都有很多"categoryID"?并且您想要显示任何在" arrayOfEnabledCategoryIDs"中包含categoryID的Location对象?
假设您有一个Location实体和一个CategoryID实体,并且它们之间存在多对多关系(locations <<--->> categories),您可以这样做:
NSArray * arrayOfEnabledCategoryIDs = ...; //these are the categories to display
NSFetchRequest * f = [[NSFetchRequest alloc] init];
[f setEntity:theEntityDescriptionForLocationObjects];
[f setPredicate:[NSPredicate predicateWithFormat:@"ANY categories.categoryID IN %@", arrayOfEnabledCategoryIDs]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5020 次 |
| 最近记录: |