• 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: storage for context: value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: storage for context: value


  • Subject: Re: storage for context: value
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 25 Jul 2013 12:38:58 -0700

On Jul 25, 2013, at 12:08 , Matt Neuburg <email@hidden> wrote:

> Well, and discussions of the issue often fail to take into account the problem of distinguishing the context on an instance-by-instance basis. Passing "self" as a context does that, obviously; but the "static void*" trick does not (there is one storage per class, not per instance of that class).

In the 'observeValueForKeyPath' scenario (keeping in mind that it's a broken API design), using 'self' is dangerous because it's not unique enough. A superclass-defined observation may cleverly try to use it too.

> If an informative data structure is to be used on an instance-by-instance basis, and if this data structure is to persist, then it seems to me that it *must* be an instance variable.


When you say "instance variable" I think there are actually 3 different possibilities:

1. You want a per-instance value, which is stored in an ivar specifically for that purpose.

2. You might get away with using the address of an ivar that's private to your class (whose value is something unrelated). The address is unique to the instance and class, because superclasses and subclasses won't be using it.

3. You might still need a per-observation-per-instance context tag, in which case #1 and #2 don't work. This is particularly relevant to the new form of 'removeObserver'.

If it were me, I would use a per-class tag (such as the static variable address) when I could, or a per-observation UID otherwise. Using a per-instance UID -- anything unique only to the level of 'self' -- seems too dangerous these days. The likelihood of the class having -- or later  adding -- multiple observations on the same thing seems too high.

_______________________________________________

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: 
 >storage for context: value (From: Matt Neuburg <email@hidden>)
 >Re: storage for context: value (From: Quincey Morris <email@hidden>)
 >Re: storage for context: value (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: NSTask interrupt exception
  • Next by Date: Observing Time
  • Previous by thread: Re: storage for context: value
  • Next by thread: NSTask interrupt exception
  • Index(es):
    • Date
    • Thread