Last active
December 28, 2015 04:09
-
-
Save jakebromberg/7440647 to your computer and use it in GitHub Desktop.
Macro to reduce boilerplate code for simple initializer methods. Your initializers must implement - commonInit, and rely entirely on that method for initialization.
This file contains 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
#define JB_COMMON_INIT(superInit) \ | |
^id (typeof(self) __self) { \ | |
if (!(__self = superInit)) return nil; \ | |
[__self commonInit]; \ | |
return __self; \ | |
}(self) | |
#endif |
This file contains 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)initWithFrame:(CGRect)frame | |
{ | |
return JB_COMMON_INIT([super initWithFrame:frame]); | |
} | |
- (id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
return JB_COMMON_INIT([super initWithCoder:aDecoder]); | |
} | |
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | |
{ | |
return JB_COMMON_INIT([super initWithStyle:style reuseIdentifier:reuseIdentifier]); | |
} | |
- (void)commonInit | |
{ | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment