Looking at self = [super init].
Looking at self = [super init].
- Subject: Looking at self = [super init].
- From: Alex Zavatone <email@hidden>
- Date: Fri, 29 May 2015 13:22:03 -0400
Was just looking at good old object initialization and came across a stupid idea.
For most object initialization, we do this:
- (id)init {
if (self = [super init]) {
// Set up stuff here.
// this could get long.
}
return self;
}
in some cases, the set up within the parens could get pretty long. In cases like that, I generally set up another method to handle that for organization, but if you're passing objects into into your init method, then you're passing more data again and the code could get less cleaner looking than it could be.
So, I thought, "why don't we check if self != [super init] and then immediately return if that is the case?"
That would change object initialization to this:
- (id)init {
if (self != [super init]) {
return;
}
// Set up stuff here.
// We don't care if this gets long.
// We really don't. This could go on and on.
return self;
}
We probably could make a little macro to replace that if clause and return statement if desired, but that's besides the point.
With regards to doing object initialization this way, is there a good reason why we don't do it this way?
I'm not smoking crack here, am I? Does this actually seem like a good idea?
Interested in your views on this.
Cheers and happy Friday,
Alex Zavatone
_______________________________________________
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