Improved error handling

This commit is contained in:
ronaldheft 2022-08-25 15:42:37 -04:00
parent 01678f2c91
commit 8c87b31e56
14 changed files with 220 additions and 141 deletions

View file

@ -9,15 +9,15 @@ import Foundation
import RealmSwift
extension Object {
func save() {
let realm = try! Realm()
try! realm.write {
func save() throws {
let realm = try Realm()
try realm.write {
realm.add(self, update: .modified)
}
}
func update(handler: () -> Void) {
try! self.realm?.write {
func update(handler: () -> Void) throws {
try self.realm?.write {
handler()
}
}
@ -33,12 +33,12 @@ extension EmbeddedObject {
}
protocol Deletable {
func delete()
func delete() throws
}
extension Deletable where Self: Object {
func delete() {
try! self.realm?.write {
func delete() throws {
try self.realm?.write {
self.realm?.delete(self)
}
}