• 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: split up alloc and init?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: split up alloc and init?


  • Subject: Re: split up alloc and init?
  • From: "Kyle Sluder" <email@hidden>
  • Date: Mon, 11 Feb 2008 03:28:25 -0500

On Feb 11, 2008 3:04 AM, John Terranova <email@hidden> wrote:
> Is this not the same question as assigning [super init]?  Can I count
> on the object that alloc returns being the exact same object after
> init... returns?

It's similar.  It's perfectly safe to split up +alloc and -init.  It
is NOT safe to assume that the return value of +alloc is the same as
the return value of -init; after all, what if -init return nil?

For your purposes, it would make sense to store the result of +alloc,
then re-assign that variable, passing the stored variable as an
argument to -init, like the following:

Foo *f = [Foo alloc];
f = [f initWithObject:f];

Since the RHS must be evaluated before the assignment, this is legal
and safe.  Whether it's supported in this specific instance, I can't
say.

--Kyle Sluder
_______________________________________________

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: split up alloc and init?
      • From: John Terranova <email@hidden>
    • Re: split up alloc and init?
      • From: "Kyle Sluder" <email@hidden>
References: 
 >split up alloc and init? (From: John Terranova <email@hidden>)

  • Prev by Date: Extended Bibliotheca Example
  • Next by Date: Re: split up alloc and init?
  • Previous by thread: split up alloc and init?
  • Next by thread: Re: split up alloc and init?
  • Index(es):
    • Date
    • Thread