【发布时间】:2014-09-09 14:01:14
【问题描述】:
我在我的 Swift 项目中使用 MagicalRecord - CoreData 库崩溃了:https://github.com/magicalpanda/MagicalRecord
首先,我在 AppDelegate.swift 中设置 MagicalRecord OK:
MagicalRecord.setupCoreDataStack() //-> This is OK. Don't crash
但是,当我想创建一个“联系人”实体实例时,我遇到了崩溃。
我的代码是下一个:
var context = NSManagedObjectContext.MR_contextForCurrentThread() // -> This is OK. Don't crash
var contact = Contact.MR_createInContext(context) // -> CRASH
所有编译都可以,但是当应用程序运行时,我会遇到下一次崩溃:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an entity named 'MyProject.Contact' in this model.' *** First throw call stack:
(0x27861f77 0x34870c77 0x27590c73 0x9b93d 0x74f28 0x75438 0x2aea6e33 0x2b09acef 0x2b09d19d 0x2b0a79f9 0x2b09ba5b 0x2e106141 0x2782881d 0x27827ae1 0x2782627f 0x27773da1 0x27773bb3 0x2aea0ae7 0x2ae9bc41 0x75ab0 0x75aec 0x34e10aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
MyProject 的键是 $(PRODUCT_NAME),我该如何解决这个问题?
亲切的问候
【问题讨论】:
-
请不要使用 MR_contextForCurrentThread。你会崩溃,它会是随机的和神秘的。不要使用它。
标签: ios core-data swift magicalrecord