我正在尝试从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'
如何访问结果中的每个实体?
答案 0 :(得分:1)
results
是可选的,这意味着您首先需要打开它。尝试使用这样:
if let results = context.executeFetchRequest(request, error: nil) {
if results.count > 0 {}
}