Skip to content

nonelse/NSTimer-Block

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

NSTimer+Block

Use blocks with NSTimer.

Example

[NSTimer scheduledTimerWithTimeInterval:0.5 repeats:YES block:^{
     // Code
}];

Creating a timer

- (instancetype)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds 
                         repeats:(BOOL)repeats block:(void (^)(void))block;

Initializes a new NSTimer object using the specified block.

  • date: The time at which the timer should first fire.
  • seconds: For a repeating timer, this parameter contains 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.
  • repeats: If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
  • block: The block to be executed when the timer fire. The block should take no parameters and have no return value.

Return: The receiver, initialized such that, when added to a run loop, it will fire at date and then, if repeats is YES, every seconds after that.

--

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds 
                repeats:(BOOL)repeats block:(void (^)(void))block;

Creates and returns a new NSTimer object and schedules it on the current run loop in the default mode.

  • 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.
  • repeats: If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
  • block: The block to be executed when the timer fire. The block should take no parameters and have no return value.

Return: A new NSTimer object, configured according to the specified parameters.

--

+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats 
                             block:(void (^)(void))block;

Creates and returns a new NSTimer object initialized with the specified block.

  • 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.
  • repeats: If YES, the timer will repeatedly reschedule itself until invalidated. If NO, the timer will be invalidated after it fires.
  • block: The block to be executed when the timer fire. The block should take no parameters and have no return value.

Return: A new NSTimer object, configured according to the specified parameters.

About

Use blocks with NSTimer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 100.0%