NSPredicate with (match OR match) AND 匹配
NSPredicate with (match OR match) AND match
我想要一个谓词:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(self isKindOfClass: %@ || self isKindOfClass: %@) AND isActive == YES", [TestClass1 class], [TestClass2 class]];
但是 () 并没有像我想象的那样在 if stmt 中工作:
if ((condition1 || condition2) && otherCondition) {
}
如果 'condition1' 或 'condition2' 为真加上 'otherCondition' 为真,则 if stmt 为真。
我可以用 NSPredicate
做到这一点吗?
[NSPredicate predicateWithFormat:@"(isActive == YES AND (class == %@ OR class == %@))", [TestClass1 class], [TestClass2 class]];
我想要一个谓词:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(self isKindOfClass: %@ || self isKindOfClass: %@) AND isActive == YES", [TestClass1 class], [TestClass2 class]];
但是 () 并没有像我想象的那样在 if stmt 中工作:
if ((condition1 || condition2) && otherCondition) {
}
如果 'condition1' 或 'condition2' 为真加上 'otherCondition' 为真,则 if stmt 为真。
我可以用 NSPredicate
做到这一点吗?
[NSPredicate predicateWithFormat:@"(isActive == YES AND (class == %@ OR class == %@))", [TestClass1 class], [TestClass2 class]];