Skip to content

Instantly share code, notes, and snippets.

@boredzo
Created January 6, 2012 23:30
Show Gist options
  • Save boredzo/1572986 to your computer and use it in GitHub Desktop.
Save boredzo/1572986 to your computer and use it in GitHub Desktop.
Initialization code
@interface AutoScrollView ()
- (id) commonInit __attribute__((objc_method_family(init)));
@property(nonatomic, assign, getter=isAutoScrolling) BOOL autoScrolling;
@property(nonatomic, retain) NSTimer *autoScrollTimer, *delayedStartScrollingTimer;
@property(nonatomic, retain) UIGestureRecognizer *tapRecognizer;
@end
@implementation AutoScrollView {
BOOL autoScrollWasDelayed;
}
@synthesize autoScrolling;
@synthesize autoScrollTimer, delayedStartScrollingTimer;
@synthesize tapRecognizer;
@synthesize delegate;
- (id) commonInit {
//(With the init attribute) Analyzer: Instance variable used while 'self' is not set to the result of '[(super or self) init...]'
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleAutoScrolling)];
[self addGestureRecognizer:tapRecognizer];
return self;
}
- (id) initWithCoder:(NSCoder *)decoder {
if ((self = [super initWithCoder:decoder])) {
self = [self commonInit];
}
//(If commonInit does not have the init attribute) Analyzer: Returning 'self' while it is not set to the result of '[(super or self) init...]'
return self;
}
- (id) initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self = [self commonInit];
}
//(If commonInit does not have the init attribute) Analyzer: Returning 'self' while it is not set to the result of '[(super or self) init...]'
return self;
}
@robrix
Copy link

robrix commented Jan 6, 2012

Why not do -(void)commonInit instead? Or even do it with a static function if you want to avoid subclasses breaking you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment