SQL的IN子句相当于Swift

时间:2016-05-21 03:34:10

标签: swift core-data

我想知道在MySQL的IN子句的Core Data / Swift中是否有任何等效的命令:

"SELECT details FROM tbl_details WHERE ticket IN (1,2,3)

1 个答案:

答案 0 :(得分:1)

这应该有效:

let list = [1, 2, 3]
let inPred = NSPredicate(format: "ticket IN %@", list)
var request = NSFetchRequest(entityName: "details")
request.returnsObjectsAsFaults = false
request.predicate = inPred

之后,以通常的方式调用context.executeFetchRequest来检索结果。