Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve nstimer retain cycle #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
solve nastier retain cycle
  • Loading branch information
_Peng Wang committed Dec 14, 2016
commit 6785e2c0a612ca02c3ff687b67c0ffec84b22014
22 changes: 20 additions & 2 deletions MZTimerLabel/MZTimerLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,28 @@ -(void)start{
_timer = nil;
}

__weak typeof(self)weakself = self;

if ([self.timeFormat rangeOfString:@"SS"].location != NSNotFound) {
_timer = [NSTimer scheduledTimerWithTimeInterval:kDefaultFireIntervalHighUse target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];

_timer = [NSTimer scheduledTimerWithTimeInterval:kDefaultFireIntervalHighUse
repeats:YES
block:^(NSTimer * _Nonnull timer) {
__strong typeof(weakself)strongself = weakself;
if (strongself) {
[strongself updateLabel];
}
}];
}else{
_timer = [NSTimer scheduledTimerWithTimeInterval:kDefaultFireIntervalNormal target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];

_timer = [NSTimer scheduledTimerWithTimeInterval:kDefaultFireIntervalNormal
repeats:YES
block:^(NSTimer * _Nonnull timer) {
__strong typeof(weakself)strongself = weakself;
if (strongself) {
[strongself updateLabel];
}
}];
}
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];

Expand Down