I'm working on a closed source Swift framework that uses Realm internally. In the process of testing this framework, I'm using the framework within an iOS app that also uses Realm.
When the framework creates it's own Realm, it uses a Realm.Configuration specific to the framework. The host app creates Realm objects using the default Realm configuration. The Realms are 'separate'.
There are a couple problems:
Is there any way to use two completely separate Realms within one app?
I may be able to specify the list of classes for the framework Realm when using RealmConfiguation's objectTypes option, but that would require any user of our framework to do the same. That seems unreasonable, and also still allows 1. above to be a problem.
Realm Swift is an easy to use alternative to SQLite and Core Data that makes persisting, querying, and syncing data as simple as working directly with native Swift objects. Deploy a sample appView documentation.
Realm is a fast, scalable alternative to SQLite with mobile to cloud data sync that makes building real-time, reactive mobile apps easy. Deploy a sample appView documentation.
There is no need to manually close a realm in Swift or Objective-C. When a realm goes out of scope and is removed from memory due to ARC , the realm is closed.
Yes, it's possible to have two separate libraries/frameworks/codebases in an app use Realm independently and keep their model objects completely separate.
If you have a collection of Realm Object
subclasses that you would like to keep private, you can mark them so they won't automatically be added to the app's default schema by adding the following static method override:
public class MyModel: Object {
public override class func shouldIncludeInDefaultSchema() -> Bool {
return false
}
}
This class will then only be added to a Realm
database if it is explicitly declared in the objectTypes
property of that Realm's Configuration
object.
This way, you can isolate all of your own Realm model classes to just your own framework, and the parent app can use Realm in the original context without any objects getting mixed up in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With