Friday, April 26, 2013

NSTimer timerWithTimeInterval invocation repeats example ios


timerWithTimeInterval :invocation:repeats:

Creates and returns a new NSTimer object initialized with the specified invocation object.
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds invocation:(NSInvocation *)invocation repeats:(BOOL)repeats
Parameters
seconds
The number of seconds between firings of the timer. If seconds is less than or equal to 0.0, this method chooses the nonnegative value of 0.1 milliseconds instead
invocation
The invocation to use when the timer fires. The timer instructs the invocation object to retain its arguments.
repeats
If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
Return Value of [NSTimer timerWithTimeInterval]
A new NSTimer object, configured according to the specified parameters.
Discussion of [NSTimer timerWithTimeInterval]
You must add the new timer to a run loop, using addTimer:forMode:. Then, after seconds have elapsed, the timer fires, invoking invocation. (If the timer is configured to repeat, there is no need to subsequently re-add the timer to the run loop.)
Example of [NSTimer timerWithTimeInterval]
NSTimer *timer = [NSTimer timerWithTimeInterval:1/3 target:self 
 selector:@selector(updateThingsOnce:) userInfo:nil repeats:YES];

[timer fire];