Comma operator abuse
Some code just doesn't deserve to have extra newlines dedicated to it. For example:
- (instancetype)init
{
[self doesNotRecognizeSelector:_cmd];
return nil;
}
That return will never get hit, but the misguided compiler rightly warns you that you never actually returned everything.
Well, the comma operator is here for you:
- (instancetype)init
{
return ([self doesNotRecognizeSelector:_cmd], nil);
}
This lets you do neater deallocs as well:
- (void)dealloc
{
if (_cfTypeRef)
_cfTypeRef = (CFRelease(_cfTypeRef), nil);
}
Written by Sergey
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Objective-c
Authors
Related Tags
#objective-c
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#