Добавлена возможность задавать путь к БД для использования App Groups
This commit is contained in:
parent
692ed39781
commit
1aea5d6144
|
|
@ -17,6 +17,9 @@ public struct RealmConfiguration {
|
|||
/// Version of database.
|
||||
public let databaseVersion: UInt64
|
||||
|
||||
/// URL of database.
|
||||
public let databaseURL: URL?
|
||||
|
||||
/// Migration block for manual migration.
|
||||
public let migrationBlock: MigrationBlock?
|
||||
|
||||
|
|
@ -35,21 +38,24 @@ public struct RealmConfiguration {
|
|||
public let shouldCompactOnLaunch: ((Int, Int) -> Bool)?
|
||||
|
||||
|
||||
/// Create an instance with specified `databaseFileName`, `databaseVersion`, `migrationBlock`.
|
||||
/// Create an instance with specified `databaseFileName`, `dataBaseURL`, `databaseVersion`, `migrationBlock`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - databaseFileName: name. See above.
|
||||
/// - databaseURL: url. See above.
|
||||
/// - databaseVersion: version. See above.
|
||||
/// - migrationBlock: migration block. See above.
|
||||
/// - encryptionKey: encryption key. See above.
|
||||
public init(
|
||||
databaseFileName: String = "Database.realm",
|
||||
databaseURL: URL? = nil,
|
||||
databaseVersion: UInt64 = 1,
|
||||
migrationBlock: MigrationBlock? = nil,
|
||||
encryptionKey: Data? = nil,
|
||||
shouldCompactOnLaunch: ((Int, Int) -> Bool)? = nil) {
|
||||
|
||||
self.databaseFileName = databaseFileName
|
||||
self.databaseURL = databaseURL
|
||||
self.databaseVersion = databaseVersion
|
||||
self.migrationBlock = migrationBlock
|
||||
self.encryptionKey = encryptionKey
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ open class RealmDAO<Model: Entity, RealmModel: RLMEntry>: DAO<Model> {
|
|||
|
||||
var config = Realm.Configuration.defaultConfiguration
|
||||
|
||||
guard let path = self.pathForFileName(configuration.databaseFileName) else {
|
||||
guard let path = configuration.databaseURL ?? self.pathForFileName(configuration.databaseFileName) else {
|
||||
fatalError("Cant find path for DB with filename: \(configuration.databaseFileName)"
|
||||
+ " v.\(configuration.databaseVersion)")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue