Swift - Sharing the underlying data model in an application group (no extension)

I'm trying to use the same kernel data model in my application as well as in the extension, but I'm not sure how to split the main data model between 2. The class uses the namespace with the class name for the base data model, so when I try to get objects in the extension, I get the inability to load the class named "".

CoreData: warning: Unable to load class with name "Dali.Alarm" for object 'Alarms'. The class was not found, using the default NSManagedObject instead.

In any case, in order not to use the namespace in the class name, or is there a way to make the extension inherit the namespace of the main project?

Core data entity

+6
source share
1 answer

I am stuck on this before. This seems to be a real problem, and it wouldn't be painful to write it as a feature request / error with Apple.

In the meantime, you can get around it in two steps. First, tag subclasses of NSManagedObject with @objc(ClassName) . Just add it above the class declaration:

 @objc(ClassName) class ClassName: NSManagedObjectSubclass { @NSManaged var name : String } 

Second, return to the managed object model and remove the namespace from the class name field in the inspector for the object you are working with.

This worked for me today after reading this: I cannot use my main data model for two purposes in a Swift project

+10
source

Source: https://habr.com/ru/post/976914/


All Articles