I have an NSPredicateEditor that is part of a preference panel for a tool that I am making.
I would like to store the user's selections just as I would any other item in the NSUserDefaults object, but when I add the Binding to the NSPredicateEditor object and run the tool, it will not keep data and further it causes the other defaults to not show. When I take away the binding and recompile, everything else comes back.
What is the best way to store the NSPredicatedEditor data as a user preference?
Thanks.
Whenever the UI of an
NSPredicateEditor
changes, those changes are immediately reflected in the editor'sobjectValue
(ie, its representedNSPredicate
). So you can just grab that predicate and archive it using anNSKeyedArchiver
. This will effectively turn the predicate into anNSData
object, which can be saved out toNSUserDefaults
.To read it back in, just grab the
NSData
object, run it through anNSKeyedUnarchiver
, andsetObjectValue:
on your predicate editor.You can probably accomplish this through bindings, though I have never tried it. You can bind the
value
of anNSPredicateEditor
to something that supplies anNSPredicate
(or anNSPredicate
inNSData
form). You'll also probably need to specify that the value transformer is theNSKeyedUnarchiveFromData
transformer.