OSX CoreData:仅针对某些实体发出:+ entityForName:在此模型中找不到名为“myEntity”的实体 [英] OSX CoreData: issue only for some entities: +entityForName: could not locate an entity named 'myEntity' in this model
问题描述
我一直在尝试把这一天算出来:(
I've been trying to figure this one out for days :(
给定:
println("\(context)")
if context == nil {
println("context is nil")
}
let boardEntity: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Board", inManagedObjectContext: context) as NSManagedObject
let cardQueueEntity: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("CardQueue", inManagedObjectContext: context) as NSManagedObject
boardEntity保存得很好,我甚至在sql文件中直接验证了这一点。
boardEntity saves fine. I've even verified this in the sql file directly.
cardQueueEntity会产生以下错误:
+ entityForName:在此模型中找不到名为CardQueue的实体
cardQueueEntity produces the following error:
+entityForName: could not locate an entity named 'CardQueue' in this model.
- println((context))显示
< NSManagedObjectContext:0x6080001dfd10& / code>
- 我已经检查过三次检查名称是否与模型匹配
- 设置断点显示崩溃发生在
cardQueueEntity
声明 - 我已经查看了sql文件以验证实体名称是否相同
- 我手动删除了我的sqllite文件(在/ library / container / ..)强制重建数据库,但结果是相同的
- 我引用了 + entityForName:在此模型中找不到名为Dogs的实体和其他人,但找不到解决方案
- 如果我注释掉电路板或更改顺序,电路板仍然可以正常工作,cardQueue不会。
-
println \(context.persistentStoreCoordinator.managedObjectModel.entitiesByName))
显示所有实体。
- println("(context)") shows
<NSManagedObjectContext: 0x6080001dfd10>
- I've tripled checked that the names match the model
- setting breakpoints reveals that the crash happens at the
cardQueueEntity
declaration - I've looked into the sql file to verify that the entity names are the same there too
- I've manually removed my sqllite files (in /library/containers/..) to force a db rebuild, but the result is the same
- I've referenced +entityForName: could not locate an entity named 'Dogs' in this model. and others but couldn't find a solution
- if I comment out boards or change the ordering, boards still works and cardQueue doesn't.
println("\(context.persistentStoreCoordinator.managedObjectModel.entitiesByName)")
shows all entities.
我使用的核心数据堆栈(基于 http://www.cimgf.com/2014/06/08/the-core-data-stack-in-swift ),
here's the core data stack i'm using (based on http://www.cimgf.com/2014/06/08/the-core-data-stack-in-swift),
@lazy var context: NSManagedObjectContext = {
let modelURL = NSBundle.mainBundle().URLForResource("Tello", withExtension: "momd")
let mom = NSManagedObjectModel(contentsOfURL: modelURL)
let psc = NSPersistentStoreCoordinator(managedObjectModel: mom)
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let storeURL = (urls[urls.endIndex-1]).URLByAppendingPathComponent("Tello.sqlite")
var error: NSError? = nil
var store = psc.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: storeURL, options: nil, error: &error)
if (store == nil) {
println("Failed to load store")
}
var managedObjectContext = NSManagedObjectContext()
managedObjectContext.persistentStoreCoordinator = psc
return managedObjectContext
}()
但我得到与默认Apple堆栈相同的问题。
but I get the same issue with the default Apple stack as well.
谢谢!
推荐答案
这可能或可能不会如果你有同样的问题,但解决了我的是将我的mac升级到Yosemite测试版,从XCode beta1到beta3。
This may or may not help you if you're having the same issue, but what resolved it for me was upgrading my mac to the Yosemite beta and from XCode beta1 to beta3.
我不能说
(对于Mavericks编辑部署目标,明确构建10.9没有修复对我来说是个问题。)
(On Mavericks editing the deployment target to explicitly build for 10.9 didn't fix the problem for me.)
这篇关于OSX CoreData:仅针对某些实体发出:+ entityForName:在此模型中找不到名为“myEntity”的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!