【发布时间】:2014-11-30 22:12:35
【问题描述】:
我在 NSMutableArray 上使用 NSPredicate,如下所示,从 XML Sheet 填充
//Get XML Data
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"breosla_db" ofType:@"xml"];
NSDictionary *xmlDoc = [NSDictionary dictionaryWithXMLFile:filePath];
//Place in Mutable Array
NSMutableArray *data = [xmlDoc valueForKeyPath:@"row"];
NSLog(@"Data %@", data[0]);
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"ID contains[c] '2'"];
NSArray *filtered = [data filteredArrayUsingPredicate:bPredicate];
日志中的数据是这样的:
Data {
ID = (
2
);
address1 = (
"123 Fake Street"
);
address2 = (
"A Sleepy Town"
);
address3 = (
);
county = (
);
licenseNo = (
12345
);
licenseType = (
"Trader"
);
licenseeName = (
"Mr. Trader"
);
nominessName = (
);
tradingName = (
"Trading Shop"
);
}
当前谓词:
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"ID contains[c] '2'"];
仅返回 ID == 2 的数据,例如不返回 12、22、42 等。
其次,我不能按例如过滤。所有包含“e”的名称:
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"tradingName contains[c] 'e'"];
每个位置的“数据”NSMutableArray 包含与日志中显示的数据相似的数据。
【问题讨论】:
标签: ios nsmutablearray nsarray nsdictionary nspredicate