什么类型返回executeFetchRequest

时间:2014-12-12 16:33:08

标签: ios core-data swift

我正在尝试从CoreData获取实体:

var request = NSFetchRequest(entityName: "Themes")
        request.returnsObjectsAsFaults = false
        var results = context.executeFetchRequest(request, error: nil)
        if results.count > 0 {}

但我得到error '[AnyObject]?' does not have a member named 'count' 如何访问结果中的每个实体?

1 个答案:

答案 0 :(得分:1)

results是可选的,这意味着您首先需要打开它。尝试使用这样:

if let results = context.executeFetchRequest(request, error: nil) {
    if results.count > 0 {}
}