Skip to content

Instantly share code, notes, and snippets.

@jakebromberg
Last active December 28, 2015 04:09
Show Gist options
  • Save jakebromberg/7440647 to your computer and use it in GitHub Desktop.
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.
#define JB_COMMON_INIT(superInit) \
^id (typeof(self) __self) { \
if (!(__self = superInit)) return nil; \
[__self commonInit]; \
return __self; \
}(self)
#endif
- (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