使用NSpredicate进行IOS NSobject深度子过滤

时间:2015-12-15 19:46:01

标签: ios objective-c subquery nspredicate nsobject

matsDataObject *notebook1 = [matsDataObject dataObjectWithName:@"Notebook 1" children:nil];
matsDataObject *notebook2 = [matsDataObject dataObjectWithName:@"Notebook 2" children:nil];

matsDataObject *computer1 = [matsDataObject dataObjectWithName:@"Computer 1"
                                                      children:[NSArray arrayWithObjects:notebook1, notebook2, nil]];
matsDataObject *computer2 = [matsDataObject dataObjectWithName:@"Computer 2" children:nil];
matsDataObject *computer3 = [matsDataObject dataObjectWithName:@"Computer 3" children:nil];

matsDataObject *computer = [matsDataObject dataObjectWithName:@"Computers"
                                                     children:[NSArray arrayWithObjects:computer1, computer2, computer3, nil]];

这是我的NSobject:

计算机名称为“计算机”,子项为“NSarray,其值为计算机1,计算机2和计算机3”

计算机1的名称为“计算机1”,子计算机“NSarray的值为Notebook 1和Notebook 2”

Trough NSpredicate我想在搜索“Notebook 1”时获取父对象“Computers”

我尝试了什么:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(children, $child, $child.children.name CONTAINS[cd] %@).@count > 0",searchText];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY children.children.name contains[cd] %@",searchText];

1 个答案:

答案 0 :(得分:0)

要关闭此问题。答案来自Willeke。

Mirror(reflecting: self)