【发布时间】:2012-02-06 15:16:20
【问题描述】:
我已经解决这个问题很长时间了,我错过了整个足球赛季,也没有看到我心爱的红人队再次输掉几乎所有的比赛。没有我的支持,即使是我心爱的阿森纳也表现不佳,所以请帮助:
我正在遍历一系列核心数据对象。我正在尝试查找主实体和子实体包含搜索词的对象。如果有,我想将它们添加到结果数组中。
现在有数百行垃圾代码被浪费了,并且永远不会被使用,因为我遵循了不同的线程并采取了错误的线索..
目前的代码是这样的:
NSLog(@"%s", __FUNCTION__);
NSMutableArray *tempArray = [NSMutableArray array];
for (NSManagedObject *object in tableViewModel.items) {
//myPredicate = [NSPredicate predicateWithFormat:@"(people.name contains[cd] %@)", searchText];
//another one for the junk heap
NSLog(@"searchText: %@", searchText); //this is ok
NSLog(@"\n\nobject is: %@\n\n", object); //this is ok
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(people.name contains[cd] %@)", searchText];
BOOL ok = [predicate evaluateWithObject:object]; // this is not ok
if (ok) {
NSLog (@"result is TRUE");
[tempArray addObject:object];
NSLog(@"\n\ntempArray: %@\n\n", tempArray);
} else {
NSLog (@"result is FALSE");
}
}
NSLog(@"out of records");
autoSearchResults = tempArray;
NSLog(@"\n\nautoSearchResults: %@\n\n", autoSearchResults);
return autoSearchResults; // return my own search array
我得到的输出如下:
object is: <MainEntity: 0x79c51cb0> (entity: MainEntity; id: 0x79c50880 <x-coredata://99B12EAD-002C-402C-99CA-CF5A328E67E5/MainEntity/p2> ; data: {
audioName = 00010206120609;
audioNo = 0;
date = "2012-02-06 11:10:00 +0000";
Main = "Main-0001 12.02.06";
interpret = nil;
keyword = "<relationship fault: 0x79c708a0 'keyword'>";
order = 0;
people = "<relationship fault: 0x79c708c0 'people'>";
place = "<relationship fault: 0x79c710b0 'place'>";
recurring = 0;
summary = Test1;
symbol = "<relationship fault: 0x79c71110 'symbol'>";
type = "<relationship fault: 0x79c71170 'type'>";
})
2012-02-06 10:00:11.454 Appkeeper[42598:16c03] result is FALSE
不知道是否需要使用谓词,谓词是否正确。我认为我没有正确测试条件。
所以任何帮助将不胜感激..
编辑 - 添加一点关系模型......
【问题讨论】:
标签: xcode core-data ios5 uisearchbar