我正在使用带有Swift 2.1和Xcode 7.2的Core数据.这段代码给了我一个无法找到实体名称的错误.这个[公司]不起作用.我有一个具有此名称的实体.
let fetchRequest = NSFetchRequest(entityName: "Company")
do {
var result = try self.moc.executeFetchRequest(fetchRequest) as! [Company]
if (result.count > 0){
companyName?.stringValue = result[0].valueForKeyPath("name") as! String
// success ...
}
else{
}
} catch let error as NSError {
// failure
print("Fetch failed: \(error.localizedDescription)")
}
Run Code Online (Sandbox Code Playgroud)