I have a custom designated initialiser like this:
- (id)initWithLocation:(CLLocation *)location
{
if (location == nil)
{
return nil;
}
self = [super init];
if (self)
{
self.location = location;
}
return self;
}
My colleagues sometimes ask me to wrap everything (apart from the return
), that follows after first curly brace pair, in an else
clause:
- (id)initWithLocation:(CLLocation *)location
{
if (location == nil)
{
return nil;
}
else
{
self = [super init];
if (self)
{
self.location = location;
}
return self;
}
}
But I am not sure. What is the point? The first if
condition is a quick death check. If the parameter is not provided, no instance is provided. This serves as enforcement for providing a parameter. else
seems superficial here as it is implied in the flow of the code.
What would be the advantage having it?