我想设置一个带有下一个子预测的复合谓词:
我正在阅读NSCompoundPredicate documentation但不明白 - 是否可以同时使用+ andPredicateWithSubpredicates:
和+ orPredicateWithSubpredicates:
将它们组合为一个提取请求中的一个谓词?< / p>
答案 0 :(得分:21)
解决这个问题:
objc:
NSPredicate *orPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[firstPredicate, secondPredicate]];
NSPredicate *andPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[thirdPredicate, fourthPredicate]];
NSPredicate *finalPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[orPredicate, andPredicate]];
[fetchRequest setPredicate:finalPredicate];
夫特:
let orPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: [firstPredicate, secondPredicate])
let andPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [thirdPredicate, fourthPredicate])
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [orPredicate, andPredicate])