To begin I am a total beginner at programming and maybe overly ambitious.
I am teaching myself Objective-C by trying to build a countdown timer app.
I have gotten the timer working fine but did so by putting all of the timer program into the view controller.
So now I am trying to make it more flexible by creating a timer class so that the view controller is only taking care of the view (if I understand correctly this is the 'correct' way of doing things).
In my timer class have have two public methods that create the NSTimer object (startTimer and resumeTimer)
which calls a private method every second: calculateTimeRemaining that calculates the time remaining and returns it
so my problem is getting the timeRemaining back to view controller so it can update the label every second.
from what I understand and have read there seem to be two ways to go about this. Either create a delegate protocol for the timer class in which the delegate would have to take care of startTimer and resumeTimer or set up a KVO for the timeRemaing object that the view controller could observe.
I have not had any experience doing either of these and am going to play around with both.
I have a few questions concerning them:
Is a KVO even a good idea for this? Will it be reliable/fast enough to get a label updated every second?
Is there some other way to use delegation in which the NSTimer object could still be created in my timer class and still return and updated timeRemaining object every sec?
Should I not pursue either of these and look into some other way of doing this?
Thanks for your help. I really am enjoying experimenting and learning which is why I am not posting any code. Really just looking for some higher level insight into possible ways of accomplishing this.
I am teaching myself Objective-C by trying to build a countdown timer app.
I have gotten the timer working fine but did so by putting all of the timer program into the view controller.
So now I am trying to make it more flexible by creating a timer class so that the view controller is only taking care of the view (if I understand correctly this is the 'correct' way of doing things).
In my timer class have have two public methods that create the NSTimer object (startTimer and resumeTimer)
which calls a private method every second: calculateTimeRemaining that calculates the time remaining and returns it
so my problem is getting the timeRemaining back to view controller so it can update the label every second.
from what I understand and have read there seem to be two ways to go about this. Either create a delegate protocol for the timer class in which the delegate would have to take care of startTimer and resumeTimer or set up a KVO for the timeRemaing object that the view controller could observe.
I have not had any experience doing either of these and am going to play around with both.
I have a few questions concerning them:
Is a KVO even a good idea for this? Will it be reliable/fast enough to get a label updated every second?
Is there some other way to use delegation in which the NSTimer object could still be created in my timer class and still return and updated timeRemaining object every sec?
Should I not pursue either of these and look into some other way of doing this?
Thanks for your help. I really am enjoying experimenting and learning which is why I am not posting any code. Really just looking for some higher level insight into possible ways of accomplishing this.