Re: Stupid objective-c question
Re: Stupid objective-c question
- Subject: Re: Stupid objective-c question
- From: Jens Alfke <email@hidden>
- Date: Wed, 21 Sep 2016 20:50:33 -0700
> On Sep 21, 2016, at 6:36 PM, Graham Cox <email@hidden> wrote:
>
> Which is yet another reason why void* is such a shitty concept. Apple could easily have insisted that parameter was id<NSObject> without any real problems, so void*… sheesh.
It’s not an object! It’s just an opaque ‘cookie’ that you can use to recognize which observer is being invoked, and specify which one to remove.
The point of using a void* is that it’s easy to generate guaranteed-unique values by taking the address of a static variable. If the context were an object, people would be likely to assume they should use -isEqual: to compare them (as half the people on this thread seem to be doing), but that’s not a good idea because it can result in false positives comparing equal-but-different objects.
Moreover, it can be hard to be sure whether you’re getting distinct objects in Obj-C, since initializers will often return unique singletons for common cases. For instance, [[NSArray alloc] init] will always return the same pointer every time it’s called, making it a terrible choice for a context.
—Jens
_______________________________________________
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