gpt4 book ai didi

objective-c - 组合 + andPredicateWithSubpredicates : and + orPredicateWithSubpredicates: in one predicate

转载 作者:太空狗 更新时间:2023-10-30 03:39:26 26 4
gpt4 key购买 nike

我想设置一个带有下一个子谓词的复合谓词:

  • id(和类型)
  • 名字(或类型)
  • 姓氏(或类型)
  • 中间名(或类型)

我正在阅读 NSCompoundPredicate documentation但理解不够清楚 - 是否可以同时使用 + andPredicateWithSubpredicates:+ orPredicateWithSubpredicates: 将它们组合为一个提取请求中的谓词?

最佳答案

这样解决的:

对象:

NSPredicate *orPredicate = [NSCompoundPredicate orPredicateWithSubpredicates:@[firstPredicate, secondPredicate]];
NSPredicate *andPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[thirdPredicate, fourthPredicate]];
NSPredicate *finalPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[orPredicate, andPredicate]];
[fetchRequest setPredicate:finalPredicate];

swift :

let orPredicate = NSCompoundPredicate(orPredicateWithSubpredicates: [firstPredicate, secondPredicate])
let andPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [thirdPredicate, fourthPredicate])
fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [orPredicate, andPredicate])

关于objective-c - 组合 + andPredicateWithSubpredicates : and + orPredicateWithSubpredicates: in one predicate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18563318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com