• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: KVC/KVO compliance of a container adding multiple objects [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVC/KVO compliance of a container adding multiple objects [SOLVED]


  • Subject: Re: KVC/KVO compliance of a container adding multiple objects [SOLVED]
  • From: Graham Cox <email@hidden>
  • Date: Wed, 2 Jul 2008 22:54:30 +1000

Thanks for that Ken, that's a very useful heads-up that I wasn't previously aware of. I was part way through changing the code when I got this, and it meant I could back out most of the changes. It's working well now... I did go with your suggestion here for - removeObjectsInArray: since it was already working that way, but thanks for the other suggestion also.

cheers, Graham



On 2 Jul 2008, at 7:51 pm, Ken Thomases wrote:

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >KVC/KVO compliance of a container adding multiple objects (From: Graham Cox <email@hidden>)
 >Re: KVC/KVO compliance of a container adding multiple objects (From: mmalc Crawford <email@hidden>)
 >Re: KVC/KVO compliance of a container adding multiple objects (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: KVC/KVO compliance of a container adding multiple objects
  • Next by Date: Re: setFirstResponder to NSTextField fails 1st time, works next
  • Previous by thread: Re: KVC/KVO compliance of a container adding multiple objects
  • Next by thread: Re: Regarding Iphone
  • Index(es):
    • Date
    • Thread