When binding an NSArrayController
's contentArray to an NSUserDefaultsController
, you have to check the "Handles Content As Compound Value" checkbox on the binding. This has become conventional wisdom, but what does the option actually do?
I wrote a small test app and could observe that with the option turned on, the whole contentArray
is passed to the binding source's setValue:forKey:
whenever you edit a property of an element in the array. When the option is off, only the element object itself is modified and the binding source is not notified.
This explains why the option is needed to make NSUserDefaultsController
work (otherwise it wouldn't notice that you had edited something in the array and never save the change). But it doesn't explain who is doing what differently exactly. Is the array controller taking charge of this option and writing back the content array when it observes a change? If so, how does it relate to the stated purpose of the option which is to "use a reversible value transformer to translate [...] compound values temporarily into smaller pieces"?
The message flow is explained here pretty well: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html#//apple_ref/doc/uid/TP40002149-186285
Here's my attempt to answer:
contentObject
, contentArray
or contentSet
binding is retrieved from the NSUserDefaultsController using valueForKeyPath:
transformedValue:
methodinverseTransformedValue:
setValue:forKeyPath:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With