From 6220e4e58e9850afaf843cdd9abeac73355eb37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81dric=20Foellmi?= Date: Sat, 31 Aug 2013 13:47:15 +0200 Subject: [PATCH 1/2] Making use of ARC by default. --- UICountingLabel.m | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/UICountingLabel.m b/UICountingLabel.m index ff25734..5d433b6 100644 --- a/UICountingLabel.m +++ b/UICountingLabel.m @@ -118,16 +118,16 @@ -(void)countFrom:(float)startValue to:(float)endValue withDuration:(NSTimeInterv switch(self.method) { case UILabelCountingMethodLinear: - self.counter = [[[UILabelCounterLinear alloc] init] autorelease]; + self.counter = [[UILabelCounterLinear alloc] init]; break; case UILabelCountingMethodEaseIn: - self.counter = [[[UILabelCounterEaseIn alloc] init] autorelease]; + self.counter = [[UILabelCounterEaseIn alloc] init]; break; case UILabelCountingMethodEaseOut: - self.counter = [[[UILabelCounterEaseOut alloc] init] autorelease]; + self.counter = [[UILabelCounterEaseOut alloc] init]; break; case UILabelCountingMethodEaseInOut: - self.counter = [[[UILabelCounterEaseInOut alloc] init] autorelease]; + self.counter = [[UILabelCounterEaseInOut alloc] init]; break; } @@ -178,13 +178,4 @@ -(void)updateValue:(NSTimer*)timer } } --(void)dealloc -{ - [_completionBlock release]; - [_formatBlock release]; - [_counter release]; - [_format release]; - [super dealloc]; -} - @end From 043d8e35c8d260daab9253a0924460993695c060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81dric=20Foellmi?= Date: Sat, 31 Aug 2013 13:47:58 +0200 Subject: [PATCH 2/2] Fixing a bug where the completion block is being called too early. --- UICountingLabel.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/UICountingLabel.m b/UICountingLabel.m index 5d433b6..9216a8d 100644 --- a/UICountingLabel.m +++ b/UICountingLabel.m @@ -148,11 +148,6 @@ -(void)updateValue:(NSTimer*)timer { [timer invalidate]; self.progress = self.totalTime; - if(self.completionBlock != nil) - { - self.completionBlock(); - self.completionBlock = nil; - } } float percent = self.progress / self.totalTime; @@ -176,6 +171,12 @@ -(void)updateValue:(NSTimer*)timer self.text = [NSString stringWithFormat:self.format,value]; } } + + if(self.progress == self.totalTime && self.completionBlock != nil) + { + self.completionBlock(); + self.completionBlock = nil; + } } @end