2017-05-10 87 views

回答

2

您可以使用NSPredicate

比較type屬性具有特定的值。

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type = %@", searchType]; 
NSArray *filterArray = [modelArr filteredArrayUsingPredicate:predicate]; 

如果你想檢查type屬性包含特定的值比

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type contains[cd] %@", searchType]; 
NSArray *filterArray = [modelArr filteredArrayUsingPredicate:predicate]; 
0

你可以使用NSPredicate,請使用此代碼

NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"SELF.name contains[cd] %@",self.searchText.text]; 
self.filteredArray = [self.hotelArray filteredArrayUsingPredicate:bPredicate]; 
NSLog(@"HERE %@",self.filteredArray);` 
0

試試這個

NSArray *uniqueNames = [modelArr valueForKeyPath:@"@distinctUnionOfObjects.type"];