为古怪的标题道歉。我有一个 Ints 数组,我想定义一个 NSPredicate,它将过滤掉 connectionType 等于数组中包含的值的项目。
所以基本上是这样的:
fetchRequest.predicate = NSPredicate(format: "connectionType IN { all items in array }
我已经找到了一些我认为可以解决这个问题的 Objective C 示例,但我刚刚进入 iOS 开发并且只使用过 Swift,所以非常感谢这里的一些帮助:)
我试过这样做:
fetchRequest.predicate = NSPredicate(format: "connectionType IN \(myIntArray)"
然而,这会返回一个 NSInvalidArgumentException。我觉得我很接近。
NSInvalidArgumentException', reason: 'Unable to parse the format string "connectionType IN [28, 28]"
如果我执行以下操作:
fetchRequest.predicate = NSPredicate(format: "connectionType IN %@", myArray)
我得到的是这个错误:
NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (connectionType IN {28, 28})'
最佳答案
你会像这样构造一个谓词:
NSPredicate(format:"connectionType IN %@", yourIntArray)
希望对您有所帮助。
关于swift - 来自数组元素的 NSPredicate IN 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35188118/