Sebastian
Sebastian

Reputation: 6404

Multiple Realms with multiple data models

Is it possible to create two different realms each one using a different data model?

For example: defaultRealm would use the client class as model and myRealm would use products class as model

Upvotes: 11

Views: 4974

Answers (2)

bdash
bdash

Reputation: 18308

As of Realm Swift v0.95.0, the set of classes a given Realm stores can be set via the objectTypes property on Realm.Configuration.

let configA = Realm.Configuration(fileURL: realmFileURL,
                                  objectTypes: [Dog.self, Owner.self])
let realmA = Realm(configuration: configA)


let configB = Realm.Configuration(fileURL: otherRealmFileURL,
                                  objectTypes: [Product.self])
let realmB = Realm(configuration: configB)

realmA can only store instances of Dog and Owner, while realmB can only store instance of Product.

Upvotes: 26

segiddins
segiddins

Reputation: 4120

Having a different set of Object subclasses in each Realm isn't yet supported, but it will come with https://github.com/realm/realm-cocoa/issues/1584.

Upvotes: 4

Related Questions