Swift 为什么Xcode会说;预期声明“;用一个箭头指向单词“quot;定时器;?

Swift 为什么Xcode会说;预期声明“;用一个箭头指向单词“quot;定时器;?,swift,xcode,Swift,Xcode,我在下面的func pauseAction行中看到一个错误,上面写着“预期声明”,还有一个箭头指向“timer” 在这种情况下,预期声明意味着代码必须位于方法/函数内部,例如 func startTimer() { timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(updateTimer), userInfo: nil, repeats: true) } func start

我在下面的
func pauseAction
行中看到一个错误,上面写着“预期声明”,还有一个箭头指向“timer”

在这种情况下,预期声明意味着代码必须位于方法/函数内部,例如

func startTimer()
{
    timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
}
func startTimer()
{
    timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
}