I'm trying to re-write a cocoapod's Objective-C delegate protocol in Swift. The cocoapod is MZTimerLabel and I'm trying to notify my View Controller when the timer has finished. Xcode tries to layout the correct syntax for me but I cannot quite understand what is is asking for. For example, when I am reading the example method I can't discern when it says timerLabel
whether that means to type 'timerLabel' or if `timerLabel' is a placeholder for my instance of the MZTimerLabel.
It looks like the protocal is telling me to call on MZTimerLabel
and then tell it what instance in my view controller to listen for (my instance is called brewingTimer
, but I can't get the Swift Syntax right. Perhaps I should declare brewingTimer.delegate = self
in my ViewDidLoad()
?
-(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime {
//time is up, what should I do master?
}
My Swift attempt:
MZTimerLabel(timerLabel(brewingTimer, finshedCountDownTimerWithTime: 5)){
//What I want to do when the timer finishes
{self.startTimer.setTitle("Ok!", forState: .Normal)
}
I get the error "use of unresolved identifier 'timerLabel'"
I'm learning programming more or less from scratch with Swift as my first language so I'm constantly having to learn to read code "backwards" in Objective C to translate it over to Swift. Also, I don't understand what "countTime" is. I've read through all of the Swift documentation and have looked through guides for method's in Objective C, but seeing an example of an actual Objective C method written in Swift would be very helpful.