0
在我的iOS應用程序中,我拉入JSON並將其設置爲數組。該陣列是這樣的:在數組級別上使用實例計數器的NSPredicate篩選器
links = {
"link_1" = {
clicks = 1;
ip = "10.0.0.0";
shorturl = "http://on.example.com/abc";
timestamp = "2013-10-30 05:56:51";
title = Example Website;
url = "http://example.com/page/1/path/";
};
"link_2" = {
clicks = 10;
ip = "10.0.0.0";
shorturl = "http://on.example.com/def";
timestamp = "2013-10-16 16:55:47";
title = "Fitbit Force Is the Smartest Fitness Tracker Yet [REVIEW]";
url = "http://mashable.com/2013/10/16/fitbit-force-review/";
};
我有以下方法設置過濾UITableView
結果:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate
predicateWithFormat:@"links.link_1.title contains[cd] %@",
searchText];
searchResults = [filterArray filteredArrayUsingPredicate:resultPredicate];
}
我需要更新predicateWithFormat
過濾器佔,link_2
,link_3
,...
問題:我如何讓過濾器匹配我的數組中的任何「級別」,其中字符串afte r link_
始終是一個正數,但可以是無限數字的數字?
我基本上需要搜索link_
級別的數組,每個正數。
'.allValues'從哪裏來?你可以給我一個例子使用我的代碼,所以我明白你的答案? - 謝謝! – adamdehaven
@adamdehaven allValues是一個NSDictionary的方法。鏈接是一個NSDictionary對象,所以你應該得到所有的值並過濾它們。爲了給你舉個例子,我需要一些答案。代碼中的filterArray變量是什麼,它是如何得到的?它如何與打印的鏈接對象相關? –
'links'對象(在我原來的問題中)實際上是'NSArray * filterArray'的'NSLog'。 'filterArray = [NSArray arrayWithObject:[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]];' – adamdehaven