• 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: KVO can be unsafe in -init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO can be unsafe in -init?


  • Subject: Re: KVO can be unsafe in -init?
  • From: Roland King <email@hidden>
  • Date: Wed, 9 Sep 2009 18:15:03 +0800


On 09-Sep-2009, at 5:02 PM, John Chang wrote:


On 9 sep 2009, at 05.03, Roland King wrote:

One thing to note, you're using a context of NULL, which I used to do all the time until I got badly bitten.

What would you recommend using as the context? I'm used to checking object/keyPath, though I noticed as you pointed out that the Xcode template does it with context.



You have to do both, check the context first, then check the the object/path and if the context is not yours, send it to the superclass. In so much code it doesn't matter, you get used to NULL and then you get a system-generated class which has its own KVO setup, or you subclass something you wrote last year and something which relies on KVO stops working and you've often torn half your code apart before you find it.


What do I use. Normally a class static, provided that's granular enough, always has been for me thus far. Either just make some static thing like a character array and take the address of it or, as I've been doing recently, use the address of the class object which I grab in a +initialize() method (taking care again to check I'm not being called for a subclass) and stuff into a static I kept for the purpose. _______________________________________________

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: KVO can be unsafe in -init?
      • From: Dave Keck <email@hidden>
References: 
 >KVO can be unsafe in -init? (From: John Chang <email@hidden>)
 >Re: KVO can be unsafe in -init? (From: Graham Cox <email@hidden>)
 >Re: KVO can be unsafe in -init? (From: John Chang <email@hidden>)

  • Prev by Date: Re: KVO can be unsafe in -init?
  • Next by Date: Re: KVO can be unsafe in -init?
  • Previous by thread: Re: KVO can be unsafe in -init?
  • Next by thread: Re: KVO can be unsafe in -init?
  • Index(es):
    • Date
    • Thread