• 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: Stupid objective-c question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid objective-c question


  • Subject: Re: Stupid objective-c question
  • From: Jeff Evans <email@hidden>
  • Date: Wed, 21 Sep 2016 21:19:48 -0700

Whoa - maybe I've had too much wine with dinner, but:

	Is it really true what Jens says,  that [[NSArray alloc]init] always returns the same pointer?
	If that is the case, how can one declare two separate arrays?

Jeff

On Sep 21, 2016, at 8:50 PM, Jens Alfke wrote:


> 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


  • Follow-Ups:
    • Re: Stupid objective-c question
      • From: Jens Alfke <email@hidden>
    • Re: Stupid objective-c question
      • From: Doug Hill <email@hidden>
References: 
 >Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Stupid objective-c question
  • Next by Date: Re: Stupid objective-c question
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread