Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Realms with multiple data models

Tags:

ios

swift

realm

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

like image 479
Sebastian Avatar asked May 27 '15 20:05

Sebastian


2 Answers

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.

like image 144
bdash Avatar answered Nov 13 '22 17:11

bdash


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.

like image 41
segiddins Avatar answered Nov 13 '22 19:11

segiddins