0
我一直在研究这个问题很久,我错过了整个足球赛季,没有看到我心爱的红人队几乎再次失去他们所有的比赛。即使我心爱的阿森纳没有得到我的支持也不太好,所以请帮助:xCode/iOS - 需要帮助制作核心数据搜索谓词
我正在遍历一系列核心数据对象。我试图找到主对象和子对象包含搜索项的对象。如果他们这样做,我想将它们添加到结果数组中。
有数以百计的垃圾代码,现在被浪费线,永远不会被使用,因为不同的线程,我跟着,并采取虚假线索..
到目前为止的代码是这样的:
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
我不知道我是否需要使用一个谓语,谓语是否正确。我认为我没有正确测试条件。
因此,任何帮助将不胜感激..
编辑 - 添加一点关系模型....
谢谢Mundi ..没有快乐..我无法得到“object.people”来解决:“在NSManagedObject类型的对象上没有找到属性的人”..但是我可以获得一个字符串值(str1),所以如果re是我可以使用的某种比较,比如“str1包含searchTerm”,那会很棒。 – 2012-02-07 19:40:56
太好了。你的错误信息确切地解释了什么是错的。您的数据模型设置不正确。检查你的xcdatamodeld并确保你的主实体和你想检查属性'name'的值的其他实体之间有一个名为'people'的一对多关系。 – Mundi 2012-02-07 19:50:39
我做..我会添加关系表到我原来的问题...我真的很感谢帮助.. – 2012-02-07 20:28:32