Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension RealmStorageContext {
func create<T: Storable>(_ model: T.Type, completion: @escaping ((T) -> Void)) throws {
guard let realm = self.realm else {
throw NSError()
}
try self.safeWrite {
let newObject = realm.create(model as! Object.Type, value: [], update: false) as! T
completion(newObject)
}
}
func save(object: Storable) throws {
guard let realm = self.realm else {
throw NSError()
}
try self.safeWrite {
realm.add(object as! Object)
}
}
func update(block: @escaping () -> Void) throws {
try self.safeWrite {
block()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.