Fix deserialization Data objects that contain structured data (array/dict)#7
Fix deserialization Data objects that contain structured data (array/dict)#7fabiosoft wants to merge 1 commit into
Conversation
|
Hey again @fabiosoft, I hope to get around to thoroughly reviewing this. In the meantime, could you take a look at the following things?
thanks! |
|
Hello!
I looked into it further and modified these lines of code because it wasn't accepting my changes and saving them when I added or removed elements. Now it works for me. Let me know which way you prefer, so I can align the patch. reference: struct UserDefaultsDomain: DefaultsModifier {
func add(_ item: PlistItem) {
let (key, value) = item.persistentRepresentation
// Write using defaults command for immediate disk persistence
writeValue(value, forKey: key)
synchronize()
}
func removeItems(for keys: Set<String>) {
for key in keys {
deleteKey(key)
}
synchronize()
}
func synchronize() {
// Flush cfprefsd cache to disk
let appID = domainName as CFString
CFPreferencesAppSynchronize(appID)
}
// ...
private func writeValue(_ value: Any?, forKey key: String) {
// defaults command only for scalar types
// ...
case let dict as [String: Any]:
userDefaults.set(dict, forKey: key)
let _: Bool = userDefaults.synchronize()
return
case let array as [Any]:
userDefaults.set(array, forKey: key)
let _: Bool = userDefaults.synchronize()
return
// ...
}
} |
Summary
Fixed an issue where array values stored in macOS defaults were displayed as empty when attempting to edit them, even though they contained data.
Problem
When opening certain preference domains, some array fields would appear as "New empty array" in the editor, despite showing a size (e.g., "235 bytes"). This made it impossible to view or modify the actual array contents through the UI.
Solution
Improved the way preference data is loaded and parsed to properly handle arrays that are stored in serialized formats. The editor now correctly recognizes and displays these values as editable arrays with their actual content.
Testing
Tested with domains containing serialized array data. Arrays now display their content correctly and can be edited as expected.