Skip navigation.
 
mlinsertObject:in<Key>AtIndex: not being called.
FROM : Paul Szego
DATE : Sun Apr 03 00:47:12 2005

Hi,

I can't get KVC working for to-many relationships when I don't expose
the NSMutableArray directly. If I provide the following indexed
accessors (for a property named "items"), it doesn't work:

-countOfItems and -objectInItemsAtIndex:
-insertObject:inItemsAtIndex: and -removeObjectFromItemsAtIndex:

If I make the "items" attribute public, or provide get/set methods,
things work. According to the documents however, this class *is* KVC
compliant. In that case, I should be able to use valueForKey: and
setValue:forKey: for this property.

Getting the value using valueForKey: works fine - it seems that an
adapter class that implements NSArray is dynamically created, and
implemented by calling the countOfItems: and objectInItemsAtIndex:
methods. Setting the value however doesn't seem to work. If I call
setValue:forKey: I get an error message

   "this class is not key value coding-compliant for the key items."

So I'm not sure what the problem is. Other areas of documentation
describe in some detail the steps taken to access a property when the
NSKeyValueCoding methods are used. None of those descriptions mention
looking for "Indexed Accessor Patterns for To-Many Properties". However
the valueForKey: default implementation certainly seems to determine
that the indexed accessors exist. In addition, statements like this one
in the Apple documentation:

"Implementing indexed accessors methods for a property makes that
property indistinguishable from an array when using key-value coding
methods."

would lead to me to expect that a similar thing should happen when
using setValue:forKey: on a to-many property.

Can anyone shed some light on this? Should it work?

Thanks, Paul.

Related mailsAuthorDate
mlinsertObject:in<Key>AtIndex: not being called. Paul Szego Apr 3, 00:47
mlRe: insertObject:in<Key>AtIndex: not being called. mmalcolm crawford Apr 3, 03:53
mlRe: insertObject:in<Key>AtIndex: not being called. Paul Szego Apr 3, 11:31
mlRe: insertObject:in<Key>AtIndex: not being called. mmalcolm crawford Apr 3, 11:51
mlRe: insertObject:in<Key>AtIndex: not being called. mmalcolm crawford Apr 3, 11:55
mlRe: insertObject:in<Key>AtIndex: not being called. Paul Szego Apr 4, 22:13