Swift - 在应用组中共享核心数据模型(w / extension) [英] Swift - Sharing Core Data Model in App Group (w/ extension)
问题描述
CoreData:warning:无法为实体
加载名为'Dali.Alarm'的类'Alarm'。找不到类,使用默认的NSManagedObject。
有没有在类名中使用命名空间,使扩展继承主项目的命名空间?
看起来像一个真正的问题,它不会伤害作为一个功能请求/ bug与苹果。
在此期间,您可以通过两个步骤实现。首先,用 @objc(ClassName)
标记你的NSManagedObject子类。只需将它插入类声明之上:
@objc(ClassName)
className:NSManagedObjectSubclass {
@NSManaged var name:String
}
其次,回到托管对象模型,并从您正在使用的实体的检查器中的类名称字段中删除命名空间。
I'm trying to use the same core data model in my app as well as an extension, but am unsure how to share the core data model between the 2. The class for the core data model uses a namespace with the classname, so when I try and fetch the objects in the extension I get the unable to load class named "" error.
CoreData: warning: Unable to load class named 'Dali.Alarm' for entity 'Alarm'. Class not found, using default NSManagedObject instead.
Is there anyway to not use a namespace in the classname, or is there a way to make the extension inherit the namespace of the main project?
I was stuck on this earlier. Seems like a real issue, and it wouldn't hurt to file it as a feature request/bug with Apple.
In the meantime, you can get around it with two steps. First, tag your NSManagedObject subclasses with @objc(ClassName)
. Simply insert it above the class declaration:
@objc(ClassName)
class ClassName: NSManagedObjectSubclass {
@NSManaged var name : String
}
Second, go back to the managed object model, and remove the namespace from the "class" name field in the inspector for the Entity you're working with.
This worked for me today, after reading this: I can't use my core data model in two targets in a Swift project
这篇关于Swift - 在应用组中共享核心数据模型(w / extension)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!