我的coredata获取查询的动态或谓词 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
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
我花了很多时间来做这件事,我是快速发展的新手,我不习惯于目标C,这就是为什么我很难转换为我在客观c中写的快速翻译.
如果可能的话,快速写下答案,任何评论和建议都将是一个很大的帮助.提前致谢
obj c – source #1
obj c – source #2
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])