Hi
I’m currently considering migrating from core data to realm, at the same time, i’m modularizing the codebase. While planning the dependency layers I got stuck with a question.
I will move my data models to external modules, but I wanted them to be agnostic of their persistence solution (realm/core data), so I don’t have to import Realm across all other modules/packages.
I thought I could mimic Core Data and have a class that interfaces with realm like this
class NSManagedUserProfile: Object {
var account: SomeModelFromExternalLibrary
var paymentMethods: [AnotherModelFromExternalLibrary]
}
This class would stay in the main app target and it would be used to get/set things from Realm, but for the rest of the other modules in the layers above I could use a dependency free UserProfile class.
The problem (and please correct me if I misunderstood the documentation) is that the properties on an Realm.Object class have to be on Realm.EmbeddedObject, which forces me to adopt EmbeddedObject in those models (account, paymentMethods) and have to import Realm in all the modules they are contained
For a second I thought Realm.EmbeddedObject was a protocol and tried to conform to it on an extension, but its a superclass.
How can I keep my models in their modules while having my Realm classes on my main app target?