On Jul 1, 2008, at 7:16 PM, mmalc Crawford wrote:

On Jul 1, 2008, at 4:33 PM, Graham Cox wrote:

I also have a number of methods that allow "things" to be added from arrays, or indexed by an index set. Is there a way to make these KVC/KVO compliant or would they all
have to call through to one or more of these methods to ensure that?

<http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/AutoVsManual.html#//apple_ref/doc/uid/20001844-178876 >

<http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>
Batch modification of collections

Actually, a recent cocoa-dev thread alerted me to the documentation hidden in the NSKeyValueCoding.h header. According to the method descriptions in there, Tiger introduced several new indexed accessor templates:

-<key>AtIndexes:
-insert<Key>:atIndexes:
-remove<Key>AtIndexes:
-replace<Key>AtIndexes:with<Key>:

which all correspond directly to NSArray/NSMutableArray methods.

So, Graham, you could use the following:

-objectsAtIndexes:
-insertObjects:atIndexes: // instead of your home-grown addObjectsFromArray:atIndexes: -removeObjectsAtIndexes: // You got this one square on. Ain't naming conventions great!
-replaceObjectsAtIndexes:withObjects:

You should probably implement your removeObjectsInArray: in terms of - [NSArray indexOfObjectIdenticalTo:] and removeObjectsAtIndexes:.

You probably already know this, but you don't _need_ to implement _every_ such method for your property. For any given method in the KVC protocol, there is some satisfactory subset that you can implement. Once you've satisfied the requirements, implementing the other methods may be nice for 1) optimization (as documented) or 2) because they are convenient for your own code to call. Of course, feel free to go whole-hog if you want, just know it's not strictly necessary.

Cheers,
Ken
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to