Dinesh
Dinesh

Reputation: 6532

Find The NSTimer is Invalidate Or not

I need to find the NSTimer Invalidate Or not in if Condition....!

Because,NSTimer once Invalidate after another Invalidate is Crash the application...!

Any one help me with us....!

Thanks..!

Upvotes: 0

Views: 190

Answers (3)

ping localhost
ping localhost

Reputation: 479

Store the timer in a variable and then check using

[timer isValid]

Upvotes: 1

Ankit Srivastava
Ankit Srivastava

Reputation: 12405

 if([timerInstance isValid]){
//then invalidate
}else{
//do something else
}

Upvotes: 2

calimarkus
calimarkus

Reputation: 9977

If you store a timer in a member variable you should retain it. Because probably you created it using timerWithTimerInterval:

Anyhow. If your reference is valid you can check it using [myTimer isValid];

If you don't retain your timer, you should at least assign nil after invalidating it.

[myTimer invalidate];
myTimer = nil;

Upvotes: 3

Related Questions