Reputation: 37581
I have a method I would like to execute (non repeating) after a time delay.
I could use performSelector:afterDelay or I could schedule an NSTimer and specify the selector as a parameter to that.
What are the advantages / disadvantages of using one over the other if the end result is the same (which is that my method will be called after the specified time delay). Is it not matter which one I use?
(In case it is relevant, my method will get called both in the foreground and when the app moves to the background during the 10 minute window available via beginBackgroundTaskWithEcpirationHandler).
TIA
Upvotes: 2
Views: 1400
Reputation: 10860
from the apple reference of NSObject class about performSelector: method
This method sets up a timer to perform the aSelector message on the current thread’s run loop. The timer is configured to run in the default mode (NSDefaultRunLoopMode). When the timer fires, the thread attempts to dequeue the message from the run loop and perform the selector. It succeeds if the run loop is running and in the default mode; otherwise, the timer waits until the run loop is in the default mode.
so if you only want to make single call, I think you can freely use performSelector:afterDelay:
Upvotes: 3