Merge pull request #19 from levanShost/master

Proper support for in-memory Realm
This commit is contained in:
Ivan Vavilov 2019-09-24 11:20:35 +03:00 committed by GitHub
commit 62cef6b3a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -19,7 +19,8 @@ open class RealmDAO<Model: Entity, RealmModel: RLMEntry>: DAO<Model> {
/// Translator for current `RLMEntry` and `RealmModel` types.
private let translator: RealmTranslator<Model, RealmModel>
private let configuration: Realm.Configuration
/// In-memory Realm instance.
private var inMemoryRealm: Realm?
// MARK: - Public
@ -285,7 +286,18 @@ open class RealmDAO<Model: Entity, RealmModel: RLMEntry>: DAO<Model> {
}
private func realm() throws -> Realm {
return try Realm(configuration: configuration)
guard configuration.inMemoryIdentifier != nil else {
return try Realm(configuration: configuration)
}
if let realm = inMemoryRealm {
return realm
}
let realm = try Realm(configuration: configuration)
inMemoryRealm = realm
return realm
}
}