Re: Looking at self = [super init].
Re: Looking at self = [super init].
- Subject: Re: Looking at self = [super init].
- From: Dave <email@hidden>
- Date: Mon, 01 Jun 2015 13:23:50 +0100
> 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?”
Totally agree, I always do it like this:
-(instanceType) init
{
self = [super init];
if (self == nil)
return nil;
// Init code here
return self;
}
I nearly prefer a fast return over using a Brace, for instance:
-(BOOL) someMethodWithParameter1:(NSString*) theParam1 andParam2:(NSString*) theParam2
{
if (theParam1 == nil)
return NO;
if (theParam2 == nil)
return NO;
// Other code here
return YES;
}
In preference to:
-(BOOL) someMethodWithParameter1:(NSString*) theParam1 andParam2:(NSString*) theParam2
{if (theParam1 != nil)
{
if (theParam2 != nil)
{
// Other code here
}
return YES;
}
return NO;
}
All the Best
Dave
_______________________________________________
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