【发布时间】:2010-12-22 18:53:48
【问题描述】:
另一种说法可能是......
NSPredicate "state.country == 'United States'"
就像
SQL "Select * from state where state.country = 'United States'
那么我该如何做这个谓词呢?
SQL "Select state.name from state where state.county = 'United States'"
原帖:
我有一个字典数组,如下所示:
lists
states
state
country
country
country
我有按国家/地区过滤状态的代码。不过,我敢打赌有一种更清洁的方法。
NSArray *states = [lists valueForKey:@"states"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"countryname == %@", selectedCountry];
states = [states filteredArrayUsingPredicate:predicate];
states = [states valueForKeyPath:@"state"];
想法?
【问题讨论】:
-
我可能遗漏了一些明显的东西,但你的结构图对我来说绝对没有意义。能举个具体的例子吗?
-
他想获取给定国家名称的状态。他搜索库比蒂诺并得到加利福尼亚,对吗?
-
是的。州有一个名称和一个国家字符串。获取具有 state.country == "United States" 的州列表。 State 类有 state.state、state.country。
标签: iphone cocoa ios nspredicate key-value-coding