But should synthesized accessors not automatically return such a proxy object?
No.
How can I get around this - write a custom accessory that just calls [super mutableArrayValueForKey...] ?
No. Deploy array accessors . When you name them, KVO will automatically post relevant notifications. So all you have to do is:
[myObject insertObject:newObject inTheArrayAtIndex:[myObject countOfTheArray]]
and the right thing will happen automatically.
For convenience, you can write the addTheArrayObject: accessory. This accessor will call one of the real array accessories described above:
- (void) addTheArrayObject:(NSObject *) newObject { [self insertObject:newObject inTheArrayAtIndex:[self countOfTheArray]]; }
(You can and should populate the appropriate class for the objects in the array instead of NSObject .)
Then instead of [myObject insertObject:โฆ] you write [myObject addTheArrayObject:newObject] .
Unfortunately, add<Key>Object: and its counterpart remove<Key>Object: are the last ones I checked, only recognized by KVO for set properties (as in NSSet), and not array properties, so you don't get free notifications from them KVO, unless you implement them on top of the accessories that it recognizes. I filed an error about this: x-radar: // problem / 6407437
I have a list of all access selector formats on my blog.
Peter Hosey Nov 20 '08 at 2:10 2008-11-20 02:10
source share