Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension RealmStorageContext {
func delete(object: Storable) throws {
guard let realm = self.realm else {
throw NSError()
}
try self.safeWrite {
realm.delete(object as! Object)
}
}
func deleteAll<T : Storable>(_ model: T.Type) throws {
guard let realm = self.realm else {
throw NSError()
}
try self.safeWrite {
let objects = realm.objects(model as! Object.Type)
for object in objects {
realm.delete(object)
}
}
}
func reset() throws {
guard let realm = self.realm else {
throw NSError()
}
try self.safeWrite {
realm.deleteAll()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment