• 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: indexed accessor properties and NSArray/NSMutableArray's
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: indexed accessor properties and NSArray/NSMutableArray's


  • Subject: Re: indexed accessor properties and NSArray/NSMutableArray's
  • From: Roland King <email@hidden>
  • Date: Wed, 06 Aug 2008 08:27:37 +0800


Roland,

Right, that's because you've defined a setter. See the search algorithm documented for mutableArrayValueForKey: at <http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueCoding_Protocol/Reference/Reference.html#//apple_ref/doc/uid/20000471-BABJFEAE>. Try removing the setter.

-Jeff

Thanks. There's always just ONE more piece of documentation to read isn't there. So here's my (possibly) last question. If you define neither the accessor methods nor a getter/setter and make mutableArrayValueByKey use direct access to the variables, will that generate KVO notifications?

My thinking was this, if you define all the accessor methods, mutableArrayValueByKey operations will use them, and their use alone generates KVO just as if you had called them directly. If you define a getter/setter only, the mutable proxy will use that and although inefficient, just using a setter method will generate a KVO notification for the whole array. In neither of those cases does the mutable proxy have to do anything special, it just calls a method which is already KVO compliant. So I'd started to see mutableArrayValueByKey as just a convenient proxy which always calls the best KVO-compliant method in your class to do the job.

If however mutableArrayValueByKey just passes down operations to the actual instance variable, that won't automatically generate a KVO notification. I need to test now whether the proxy, in that case, having no 'automatic KVO notification generating method' to call, calls the mutator method on the variable directly and and also sends out a notification on your behalf. I'll do that test tonight to try to complete my mental picture.

I'd say that with the advent of @property and @synthesize, it's very easy to make an array property with a getter/setter, find it works just fine with an array controller, not add the indexed accessors, but not realize that behind the scenes you are creating and destroying whole arrays every time. Worse still, if you have other things observing those arrays, every time you add or remove something, the notification you get is a whole-array change, which would lead to tearing down all the observations on the contents of the old array, and adding new observers on the contents of the new array.
_______________________________________________


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


  • Follow-Ups:
    • Re: indexed accessor properties and NSArray/NSMutableArray's
      • From: Jeff Johnson <email@hidden>
References: 
 >indexed accessor properties and NSArray/NSMutableArray's (From: Roland King <email@hidden>)
 >Re: indexed accessor properties and NSArray/NSMutableArray's (From: Jeff Johnson <email@hidden>)
 >Re: indexed accessor properties and NSArray/NSMutableArray's (From: Roland King <email@hidden>)
 >Re: indexed accessor properties and NSArray/NSMutableArray's (From: Jeff Johnson <email@hidden>)

  • Prev by Date: Re: Using performSelector: on super
  • Next by Date: Re: Localize App Title?
  • Previous by thread: Re: indexed accessor properties and NSArray/NSMutableArray's
  • Next by thread: Re: indexed accessor properties and NSArray/NSMutableArray's
  • Index(es):
    • Date
    • Thread