diff --git a/AutoCat/Controllers/Location/EventsController.swift b/AutoCat/Controllers/Location/EventsController.swift index c3352c8..f2789d5 100644 --- a/AutoCat/Controllers/Location/EventsController.swift +++ b/AutoCat/Controllers/Location/EventsController.swift @@ -345,12 +345,9 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele func update(vehicle: Vehicle) -> Bool { do { if let realm = self.vehicle?.realm { - try realm.write { - do { - try ExceptionCatcher.catch { realm.add(vehicle, update: .all) } - } - catch { - self.showAlert(title: "Error updating vehicle", message: error.localizedDescription) + try ExceptionCatcher.catch { + try realm.write { + realm.add(vehicle, update: .all) } } } else { @@ -361,7 +358,8 @@ class EventsController: UIViewController, UITableViewDataSource, UITableViewDele HUD.hide() return true } catch { - HUD.show(error: error) + HUD.hide() + self.show(error: error) print(error) return false } diff --git a/AutoCat/Controllers/SearchController.swift b/AutoCat/Controllers/SearchController.swift index f5333b6..ea0e72d 100644 --- a/AutoCat/Controllers/SearchController.swift +++ b/AutoCat/Controllers/SearchController.swift @@ -162,13 +162,8 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe do { let realm = try Realm() if realm.object(ofType: Vehicle.self, forPrimaryKey: vehicle.getNumber()) != nil { - try? realm.write { - do { - try ExceptionCatcher.catch { realm.add(newVehicle, update: .all) } - } - catch { - self.showAlert(title: "Error updating vehicle", message: error.localizedDescription) - } + try realm.write { + realm.add(newVehicle, update: .all) } } } catch { @@ -176,7 +171,7 @@ class SearchController: UIViewController, UISearchResultsUpdating, UITableViewDe self.show(error: error) } - let frozenVehicle = newVehicle.freeze() + let frozenVehicle = newVehicle.realm != nil ? newVehicle.freeze() : newVehicle self.datasource.set(item: frozenVehicle, at: indexPath) self.updateDetailController(with: frozenVehicle) } onError: { err in