Ios scheduleTimerWithTimeInterval in time

I want to use scheduleTimerWithTimeInterval to perform a periodic task for a specific amount of time, say, one hour. but how to implement in your code. Here is my code:

timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(doSomething:) userInfo: nil repeats: YES]; 
+6
source share
1 answer

Suppose for a minute.

Here is a simple scenario

 int remainingCounts; NSTimer *timer; timer = [NSTimer scheduledTimerWithTimeInterval:1 target:(self) selector:@selector(countDown) userInfo:nil repeats:YES]; remainingCounts = 60; // int remainingCounts ;... 

The method is called every second.

 -(void)countDown { NSLog(@"%d", remainingCounts); // Do Your stuff...... if (--remainingCounts == 0) { //[self dismissViewControllerAnimated:YES completion:nil]; [timer invalidate]; } } 
+5
source

Source: https://habr.com/ru/post/947788/


All Articles