From 5c76158729cf2a1e00cc3d17a4f15bcd400bdd73 Mon Sep 17 00:00:00 2001 From: ronaldheft Date: Thu, 25 Aug 2022 16:55:35 -0400 Subject: [PATCH] Fix holding onto frozen Realm reference --- ios/App/Shared/util/Store.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ios/App/Shared/util/Store.swift b/ios/App/Shared/util/Store.swift index 56fe7ad1..6073f2d7 100644 --- a/ios/App/Shared/util/Store.swift +++ b/ios/App/Shared/util/Store.swift @@ -9,10 +9,17 @@ import Foundation import RealmSwift class Store { - private static var _serverConfig: ServerConnectionConfig? public static var serverConfig: ServerConnectionConfig? { get { - return _serverConfig + do { + // Fetch each time, as holding onto a live or frozen realm object is bad + let index = Database.shared.getLastActiveConfigIndex() + let realm = try Realm() + return realm.objects(ServerConnectionConfig.self).first(where: { $0.index == index }) + } catch { + debugPrint(error) + return nil + } } set(updated) { if updated != nil { @@ -20,9 +27,6 @@ class Store { } else { Database.shared.setLastActiveConfigIndexToNil() } - - // Make safe for accessing on all threads - _serverConfig = updated?.freeze() } } }