项目清单
所以我试图在 Swift 中设置一个具有多个条件的请求。SQL 等价于:
select BOARDID
from BOARD
where BOARDID not like "someBoard"
and BOARDID not like "anotherBoard"
..
我有一个字符串数组,我正在尝试遍历每个字符串以创建一个 subPredicate,将其添加到 CompoundPredicate,然后使用该 CompoundPredicate 创建一个获取请求:
let openBoards = ["someBoard", "anotherBoard", "etc"],
request = NSFetchRequest(entityName: "Board")
var openBoardsSubPredicates: Array = [],
error: NSError? = nil
for board in openBoards {
var subPredicate = NSPredicate(format: "boardID not like '\(board)'")
openBoardsSubPredicates += subPredicate
}
request.predicate = NSCompoundPredicate.andPredicateWithSubpredicates(openBoardsSubPredicates)
但是,它在 var subPredicate 行失败..
谢谢!