(void)filterListForSearchText:(NSString *)searchText
{
NSPredicate *filterPredicate = [NSPredicate
predicateWithFormat:@"SELF.name contains[cd]%@" ,searchText];
self.searchResults = [NSMutableArray arrayWithArray:[self.devices
filteredArrayUsingPredicate:filterPredicate]];
[self.tableView reloadData];
}
其中self.device日志是:::
数组是,
(
"<NSManagedObject: 0x7ffa32caab60> (entity: Device; id:
0xd000000000080000 <x-coredata://7EE6EBA4-6F15-49D8-B994-2E02379A75CD
/Device/p2> ; data: {\n company = c1;\n name = apple;\n version =
v1;\n})",
"<NSManagedObject: 0x7ffa32cb4100> (entity: Device; id: 0xd0000000000c0000 <x-coredata://7EE6EBA4-6F15-49D8-B994-2E02379A75CD/Device/p3> ; data: {\n company = \"com 2\";\n name = asad;\n version = v2;\n})",
"<NSManagedObject: 0x7ffa32cb4160> (entity: Device; id:
0xd000000000100000 <x-coredata://7EE6EBA4-6F15-49D8-B994-2E02379A75CD
/Device/p4> ; data: {\n company = \"company 3\";\n name = abbas;\n
version = v3;\n})",
"<NSManagedObject: 0x7ffa32ca8810> (entity: Device; id:
0xd000000000140000 <x-coredata://7EE6EBA4-6F15-49D8-B994-2E02379A75CD
/Device/p5> ; data: {\n company = ccc;\n name = pakistan;\n version
= vvv;\n})",
"<NSManagedObject: 0x7ffa32ca8870> (entity: Device; id:
0xd000000000180000 <x-coredata://7EE6EBA4-6F15-49D8-B994-2E02379A75CD
/Device/p6> ; data: {\n company = bbyiww;\n name = pine;\n version
= vvvrre;\n})"
)
答案 0 :(得分:0)
像这样改变你的谓词
bin\Debug\
答案 1 :(得分:0)
你可以实现它:
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"(value1 != 0) AND (value2 == %@)", [NSNumber numberWithBool:YES]];
OR
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"value1 contains[cd] %@ OR value2 contains[cd] %@", value1, value2];