or
我的coredataget
查询的动态谓词
var predicate = [NSPredicate]()
//this three is or
predicate.append(NSPredicate(format: "item_parent_id = %i", 1))
predicate.append(NSPredicate(format: "item_parent_id = %i", 3))
predicate.append(NSPredicate(format: "item_parent_id = %i", 5))
// but this one is and
predicate.append(NSPredicate(format: "price_date CONTAINS[cd] %@", 'timestamp'))
var compound = NSCompoundPredicate.orPredicateWithSubpredicates(predicate)
前三个约束条件是针对OR运算符,最后一个约束条件是AND
我为此花了很多时间,我是快速开发的新手,而且我不习惯Objective C,这就是为什么我很难转换为我在目标C中发现的内容的过程。
如果可能的话,迅速写出答案,任何评论和建议都会有很大帮助。提前致谢
如果要查找类似的操作(a OR b OR c) AND d
,则需要两个复合谓词:
var orList = [NSPredicate]()
//this three is or
orList.append(NSPredicate(format: "item_parent_id = %i", 1))
orList.append(NSPredicate(format: "item_parent_id = %i", 3))
orList.append(NSPredicate(format: "item_parent_id = %i", 5))
let orPredicate = NSCompoundPredicate.orPredicateWithSubpredicates(orList)
// but this one is and
let other = NSPredicate(format: "price_date CONTAINS[cd] %@", 'timestamp')
let compound = NSCompoundPredicate.andPredicateWithSubpredicates([orPredicate, other])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句