Skip to content

Instantly share code, notes, and snippets.

@landonf
Last active December 11, 2015 11:48
Show Gist options
  • Save landonf/4596193 to your computer and use it in GitHub Desktop.
Save landonf/4596193 to your computer and use it in GitHub Desktop.
Avoiding the default [super init] boilerplate:
- (id) initWithObject: (id) object {
PLSuperInit();
_object = object;
return self;
}
/**
* @ingroup macros
*
* Call the superclass' default zero-argument initializer, returning nil if the superclass' initializer
* returns nil.
*
* This macro is equivalent to:
*
* @code
* if ((self = [super init]) == nil)
* return nil;
* @endcode
*
* @par Example Usage
*
* @code
* - (id) initWithString {
* PLSuperInit();
* }
* @endcode
*/
#define PLSuperInit() do { \
if ((self = [super init]) == nil) {\
return nil; \
} \
} while (NO)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment