【发布时间】:2020-04-06 15:16:17
【问题描述】:
import UIKit
class ViewController: UIViewController {
var timer:Timer?
@objc func onTimerFires() {
var timeLeft:Int = timeR()
timeLeft -= 1
print("\(timeLeft) seconds left")
if timeLeft <= 0 {
timer!.invalidate()
timer = nil
}
}
@IBAction func hardnessSelected(_ sender: UIButton) {
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(onTimerFires), userInfo: nil, repeats: true)
let eggTimes:[String:Int] = [
"Soft":5,
"Medium":7,
"Hard":12,
]
let hardness = sender.currentTitle!
func timeR() -> Int {
if eggTimes[hardness]! == 5{
return(120)
}
else if eggTimes[hardness]! == 7{
return(420)
}
else {
return(720)
}
}
print(eggTimes[hardness]!)
}
}
我无法拉出嵌套函数,有没有办法进行内部函数调用。谢谢。
【问题讨论】:
标签: swift function-call nested-function