Quote:
Originally Posted by aryaxt
I have an nstimer in my vewcontroller, and the property of this timer is set to assign.
Does setting an nstimer to nil also stop the timer if running?
|
No, you need to use [timer invalidate] to stop the timer from running.
You don't have to retain a running timer since the system retains it, so using an assign property is reasonable.
I would suggest writing a custom setter for your property, like this;
Code:
- (void) setmyTimer: (NSTimer*) newValue;
{
if (myTimer != nil)
[myTimer invalidate];
myTimer = newValue;
}
Then, if you assign a new value to the timer, and the property already contains a value, the setter will invalidate it and save the new one in it's place. To stop a running timer, just say
Code:
self.myTimer = nil;
If you use the approach above, always use property notation to change the property value (e.g. self.myTimer = newTimer; or [self setTimer: newTimer]