2

iOS: scheduled NSTimer versus performSelector with delay

There are a few times when a little one-off delay in providing UI interaction or animation provides some polish to your UX in an iOS application. There are two ways that one can go about doing this:

[NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self
                                     selector:@selector(turnOffSpinner:)
                                     userInfo:nil
                                     repeats:NO];
// or
[self performSelector:@selector(turnOffSpinner:) withObject:nil afterDelay:1.0];

They work in the same way, and since there is no repeat (no nth time to consider, etc.) I don’t know if there is really a difference here besidesĀ preferenceĀ or code appearance. I can’t invalidate the performSelector of course.

I am curious if anyone has an opinion on this type of use case or not.

Personally I like the performSelector path for this type of thing – it’s cleaner in appearance and communicates the idea a bit better. To me at least.

Popularity: 14%