1
    func timerRuns(addTimeValue: Int = 1) {
    if let timeLabelInt = Int(timeLabel.text!) {
        if timeLabelInt + addTimeValue > 0 {
            timeLabel.text = String(timeLabelInt + addTimeValue)
        }
    }
}

when I debug this function when I don't send a value to the parameter it equals to 106102873578432.. any idea? Thanks!

(Im calling this function from the Timer.scheduledTimer method)

shallowThought
  • 19,212
  • 9
  • 65
  • 112
  • 3
    The timer callback is called with exactly one argument, and that is (a pointer to) the timer itself. See for example https://stackoverflow.com/questions/24889279/passing-parameters-to-a-method-called-by-nstimer-in-swift. – Martin R May 30 '17 at 18:58
  • ohhh, nice to know, so there is a way to ignore that pointer and use that default parameter? – Dudu Butbul May 30 '17 at 19:20
  • @DuduButbul Default parameter values are a static feature of Swift – the value expressions are simply inserted by the compiler at the call-site. There doesn't exist a `func timerRuns()` version of your function, so the Obj-C runtime cannot possibly call it (i.e it can't be dynamically called with the default parameter value). You'd need to add another overload for that. – Hamish May 30 '17 at 20:01
  • @Hamish so you suggest to add another function timerRuns without parameters? – Dudu Butbul May 30 '17 at 20:11
  • @DuduButbul And then have that one chain to `timerRuns(addTimeValue:)`, yup. – Hamish May 30 '17 at 20:15
  • @hamish I did it but when I call it from scheduledTimer it says `Ambiguous use of 'timerRuns'` – Dudu Butbul May 30 '17 at 20:17
  • @DuduButbul You'll need to disambiguate the selector – compare https://stackoverflow.com/q/35658334/2976878 – Hamish May 30 '17 at 20:26
  • @Hamish works for me, Thanks! – Dudu Butbul May 30 '17 at 20:53

0 Answers0