fix: prevent crash from force unwrap in UTMRegistry

Replace unsafe force unwraps with compactMap and direct value iteration
to prevent crashes during concurrent registry access.

- Line 41: Use compactMap instead of entries[key]!
- Line 126: Iterate entries.values instead of force-unwrapping by key
This commit is contained in:
Casey
2026-05-05 23:18:36 +02:00
parent e4a4c34b67
commit d6b34cec93
+4 -4
View File
@@ -37,8 +37,9 @@ class UTMRegistry: NSObject {
@Published private var entries: [String: UTMRegistryEntry] {
didSet {
let toAdd = entries.keys.filter({ !changeListeners.keys.contains($0) })
for key in toAdd {
let entry = entries[key]!
.compactMap { entries[$0] }
for entry in toAdd {
let key = entry.uuid.uuidString
changeListeners[key] = entry.objectWillChange
.debounce(for: .seconds(1), scheduler: DispatchQueue.global(qos: .utility))
.sink { [weak self, weak entry] in
@@ -122,8 +123,7 @@ class UTMRegistry: NSObject {
/// - Parameter entries: All entries to commit
private func commitAll(entries: [String: UTMRegistryEntry]) {
var newSerializedEntries: [String: Any] = [:]
for key in entries.keys {
let entry = entries[key]!
for entry in entries.values {
commit(entry: entry, to: &newSerializedEntries)
}
serializedEntries = newSerializedEntries