• 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: [Foo new] vs [[Foo alloc] init]:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Foo new] vs [[Foo alloc] init]:


  • Subject: Re: [Foo new] vs [[Foo alloc] init]:
  • From: Gregory Weston <email@hidden>
  • Date: Sun, 17 Feb 2008 17:28:49 -0500


On Feb 17, 2008, at 3:06 PM, Bill Bumgarner wrote:

On Feb 17, 2008, at 11:15 AM, Gregory Weston wrote:
See what you're saying? +alloc *or* +allocWithZone:.

See the subject? +alloc. It does not say anything about +allocWithZone:.

See this code?

@interface MyTest : NSObject
@end

@implementation MyTest
+ (id)alloc
{
 NSLog(@"allocating");
 return [super alloc];
}
@end

You would have to override +allocWithZone: to have any kind of reliable behavior.

Or you could just not assume that something which hasn't been explicitly stated in the docs is guaranteed. That's what I've been trying to say: The only promise the documentation makes about new, alloc and allocWithZone is that they're peers. It doesn't say a peep about any of them invoking any of the others to achieve that equivalence. That lack of explicit promise - the utter inability to make such a promise in general - is why it's wrong to say without a whole lot of caveats that one technique is precisely equivalent to another. Looking at the implementation of a method, rather than the interface, as it exists today and saying "you can count on this" is an outright rejection of one of the core concepts of OO.


+alloc is a cover for +allocWithZone: with a NULL zone. Not that you would know that from the documentation, unfortunately.

Which means, like the current behavior of new, that's an implementation detail that shouldn't really be relied on.


Without assuming anything, you would have to override both allocator methods; +alloc and +allocWithZone:.

So what you're saying is that [Foo new] isn't actually reliably equivalent to [[Foo alloc] init]? That all we can really assume about the default implementation of +new is that it performs behavior functionally equivalent to that performed by the default +alloc (and then invokes init)?
_______________________________________________


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: [Foo new] vs [[Foo alloc] init]:
      • From: j o a r <email@hidden>
    • Re: [Foo new] vs [[Foo alloc] init]:
      • From: Bill Bumgarner <email@hidden>
References: 
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Gregory Weston <email@hidden>)
 >Re: [Foo new] vs [[Foo alloc] init]: (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Re: NSPreferencePane IB Problem (fixed)
  • Next by Date: Re: Exited abnormally: Broken pipe
  • Previous by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Next by thread: Re: [Foo new] vs [[Foo alloc] init]:
  • Index(es):
    • Date
    • Thread