【发布时间】:2014-07-26 18:00:13
【问题描述】:
列表项
所以我试图在 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 行失败..
谢谢!
【问题讨论】:
-
“失败”是什么意思?更加详细一些。是编译器错误吗?它在运行时崩溃吗?它报告了什么错误?
-
我收到以下两个错误:1.引发了未捕获的异常,2.无法解析格式字符串“boardID not like 'someBoard'”
标签: core-data swift nspredicate nscompoundpredicate