Q:

stop NSTimer causes error

I used the codes below to stop a NSTimer
-(void)stopTimer:(NSTimer*)timer;
{
    if(!timer) return;
    if([timer isValid])
    {

        [timer invalidate];
        timer = nil;

    }

}

sometimes it causes 'EXC Bad Access"
sometimes I got
 -[__NSCFType isValid]: unrecognized selector sent to instance 0x6298eb0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType isValid]: unrecognized selector sent to instance 0x6298eb0'

I think my codes has checked if the NSTimer is valid, if sure then executes 'invalidate'
Welcome any comment

A:

If you are invalidating the timer anywhere else then this will occur
Make sure everywhere that the timer is released or invalidated the pointer to it is nil
you could also add a second check of 
if ([timer isKindOfClass:[NSTimer class]])

