mirror of
https://github.com/utmapp/UTM.git
synced 2026-10-12 02:24:01 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user