objective c - Editable table view bound to NSArrayController bound to NSUserDefaultsController -


i have simple model foo represents user preference , encapsulates nsstring , nsnumber. want store array of foo’s in user defaults persist between launches of application; , i’d display them in table view such user can add, remove, , edit them. solution seemed pretty straightforward bindings, it’s proving impossible me working.

when application launches register nsuserdefaults keyed archive of array of initial foo’s. in xib have array controller content array bound shared user defaults controller’s values controller key; key path of foos; ‘handles content compound value’ checked; , nskeyedunarchivefromdata value transformer. table view in turn bound array controller , columns of table properties of foo.

this works when foo’s added , removed array—the foos key in user defaults updated reflect new contents of array. problem changes properties of individual foo don’t trigger array written user defaults. believe reason discussed in ‘to-many relationships’ section of ‘registering dependent keys’ in key-value observing programming guide: changes array controller’s array observed, changes properties of contained elements aren’t.

despite recognizing problem can’t life of me figure out in order make work. when observe change on foo object need inform , message such entire array written user defaults—nsuserdefaults, nsuserdefaultscontroller, nsarraycontroller? wish apple documentation had more cursory mention of problem , provided actual example code solve it—i’ve tried , can’t find magic incantation.

this similar how notified of changes models via nsarraycontroller can’t make conceptual leap between he’s doing custom view , use of bind:toobject:withkeypath:options:.

thanks! :)

i'm ios developer forgive me if there's aspect of i'm missing due ios not supporting cocoa bindings.

i not tell sounds though want notification when property of foo modified can signal change foos array , have nsuserdefaults refresh saved array. correct?

assuming understand scenario, , given that, said, modifying array (i.e. adding/removing foo's inside 'foos' signaling change, seems obvious need signal foos has been updated time individual property updated.

to that, need fire off kvo notification when property changes. override setters inside foo - properties care observing. , send notification there.

but how yo this? usual pattern send kvo notification goes (for property called openingbalance:

[self willchangevalueforkey:@"openingbalance"]; _openingbalance = thebalance; [self didchangevalueforkey:@"openingbalance"]; 

but in case want send notification property 'foos' has changed. , not property on foo. there's nothing says notification has specific property (or @ least nothing i'm aware of). but, don't want foo know it's composed inside 'foos' property somewhere else.

so, how using straight nsnotification? create generic method fire 'foo' updated notification inside foo -- subclass setters, , fire notification whenever modify foo property.

in turn, inside object owns 'foos' subscribe notification , either directly update nsuserdefaults or, there, fire off kvo notifications 'foos' there.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -