I have a ViewController with a 'Note' object as an instance variable. This variable is set before the ViewController appears.
The Note object contains a customFields NSMutableDictionary<String, String>.
I bind each value of the dictionary to a NSTextField of the dictionary in viewWillAppear :
newTextField.bind(.value, to: self, withKeyPath: "note.customFields.\(key)", options: nil)
The textField correctly displays the value from note.customFields.\(key).
BUT, if the user edits that value and saves, the change is not reflected in the dictionary.
The save() (basically a managedobjectcontext.save()) method has been tested with other fields (bound to other non-dictionary instance variables) and works properly.
Is there a reason why the dictionary does not receive the updated value?
Thanks for the help :-)
EDIT: here is the definition of customFields in the model:

The issue here is the combination of mutable type (here
NSMutableDictionary) and Core Data.This post helped: Core Data not saving transformable NSMutableDictionary
And this article helped as well: https://medium.com/@rohanbhale/hazards-of-using-mutable-types-as-transformable-attributes-in-core-data-2c95cdc27088
Solution summary
As proposed in the first link up-mentioned, I tried informing Core Data of changes in my
NSMutableDictionaryusingnote.valueDidChange(forKey: "customFields")but it did not work properly.So I ended up using the second proposition in the first link, which is the same as the solution proposed in the second linked:
NSDictionaryas transformable typemutableDict = dictionary.mutableCopy(), and then save back to the nsdictionary :dictionary = mutableDict.copy()NSTextFieldbinding, the bindings will work for displaying the value, but for updating the value, you have to do it without bindings (whenever your view will disappear or when textfield ends editing)Hope that helps!