NSTimer for the newbies

If objective C is a computer language living in the Xcode system nurtured by physical machinery things, then what is time inside of it? That was overwhelming. To simply display time, NSTimer does it.

-(NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:self selector:(tobeSelectedMethod) userInfo:nil repeats:(BOOL)yesOrNo;

While there are other NSTimer class methods we could use to execute the motion of time passing, but this is the preferred option because it starts timing once called.

[super viewDidLoad];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
userInfo:nil repeats:YES];
-(NSString *)startTimer1{
//gap is an integer in between time interval value.
self.gap = 1;
self.interval1 += self.gap;
  //format self.interval
NSUInteger seconds = (int)self.interval;
NSUInteger minutes = seconds/60;
NSUInteger hours = minutes/60;
NSString *timeString1 = [NSString stringWithFormat:@"%lu:%lu:%lu",(unsigned long)hours, minutes%60, seconds%60];

//display the time with UILabel
self.timeLabel.text = timeString1;
return timeString1;

…and it stops this timing by:

[self.timer invalidate];

Most bits in the above code are self-explanatory and mentioned in many tutorials:
scheduledTimerWithTimeInterval takes NSInterval, which acts just like the second in real time. @selector activates another method, which relies on the NSTimer to fulfill itself. repeats:YES asks the timer to expand it’s interval 1 continuously as a rhythm. Therefore, we have the every second ticking, tic, tic, tic … Think about a metronome: a finger pushes the ticker pole( scheduledTimer…), the weight on the ticker pole controls the beat (WithTimeInterval…), wind the nob on the side (repeats:YES). selector:@selector play the music on the beat!

This is an example on how NSTimer method scheduledTimerWithTimeInterval varies if assigning :
interval to 1, 0.1,1. gap to 1,1,10. https://github.com/guangLess/nstimer-for-theNewbies

Notice: TimeInterval: can be different numbers. 1 is 1 second. 10 is 10 second. If it is 10, then there are 10 second in-between each time tick. self.gap = 1 can be other numbers as well. Play!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.