/* 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