如何使用 NSPredicate 过滤另一个 class 属性?
How to filter on another class property with NSPredicate?
我关注类
EntityOne
- Property1 : string
- Property2 : int
- Property3 : Array of EntityTwo
EntityTwo
- Property1 : string
- Property2 : int
我想编写一个 NSPredicate
,当我在包含 EntityOne
个对象的数组上执行它时,它会在 EntityTwoObj.property1
上进行过滤。
可能吗?
我试过以下方法:
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:
@"Property1 CONTAINS[cd] %@
OR Property2 CONTAINS[cd] %@
OR Property3.Property1 CONTAINS[cd] %@",
newString, newString, newString];
但它不起作用。
如果我删除了最后一个过滤器,那么它就可以正常工作了。
谢谢@Larm,我可以通过在谓词中添加 ANY
运算符来解决它。
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:
@"Property1 CONTAINS[cd] %@
OR Property2 CONTAINS[cd] %@
OR ANY Property3.Property1 CONTAINS[cd] %@",
newString, newString, newString];
我关注类
EntityOne - Property1 : string - Property2 : int - Property3 : Array of EntityTwo EntityTwo - Property1 : string - Property2 : int
我想编写一个 NSPredicate
,当我在包含 EntityOne
个对象的数组上执行它时,它会在 EntityTwoObj.property1
上进行过滤。
可能吗?
我试过以下方法:
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:
@"Property1 CONTAINS[cd] %@
OR Property2 CONTAINS[cd] %@
OR Property3.Property1 CONTAINS[cd] %@",
newString, newString, newString];
但它不起作用。
如果我删除了最后一个过滤器,那么它就可以正常工作了。
谢谢@Larm,我可以通过在谓词中添加 ANY
运算符来解决它。
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:
@"Property1 CONTAINS[cd] %@
OR Property2 CONTAINS[cd] %@
OR ANY Property3.Property1 CONTAINS[cd] %@",
newString, newString, newString];