Re: split up alloc and init?
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