-
-
Save ennioma/3bffdc093cbd82f877a898f83ed24349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Storage config options */ | |
public enum ConfigurationType { | |
case basic(url: String?) | |
case inMemory(identifier: String?) | |
var associated: String? { | |
get { | |
switch self { | |
case .basic(let url): return url | |
case .inMemory(let identifier): return identifier | |
} | |
} | |
} | |
} | |
class RealmStorageContext: StorageContext { | |
var realm: Realm? | |
required init(configuration: ConfigurationType = .basic(url: nil)) throws { | |
var rmConfig = Realm.Configuration() | |
rmConfig.readOnly = true | |
switch configuration { | |
case .basic: | |
rmConfig = Realm.Configuration.defaultConfiguration | |
if let url = configuration.associated { | |
rmConfig.fileURL = NSURL(string: url) as URL? | |
} | |
case .inMemory: | |
rmConfig = Realm.Configuration() | |
if let identifier = configuration.associated { | |
rmConfig.inMemoryIdentifier = identifier | |
} else { | |
throw RealmStorageError.inMemoryIdentifierMissing | |
} | |
} | |
try self.realm = Realm(configuration: rmConfig) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment