Last active
December 11, 2015 11:48
-
-
Save landonf/4596193 to your computer and use it in GitHub Desktop.
Avoiding the default [super init] boilerplate:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id) initWithObject: (id) object { | |
PLSuperInit(); | |
_object = object; | |
return self; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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