How do I solve this error "Argument of ‘#selector’ cannot refer to local function ‘updateTimer()’", trying to make countdown timer in swift 5.1

import UIKit

class ViewController : UIViewController {

let eggTimes = ["Soft": 300, "Medium": 420, "Hard": 720]

var secondsRemaining = 60

@IBAction func hardnessSelected(_ sender: UIButton) {
    let hardness = sender.currentTitle!
    secondsRemaining = eggTimes[hardness]!
    Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
    func updateTimer() {
        if secondsRemaining > 0 {
            print("\(secondsRemaining) seconds.")
            secondsRemaining -= 1

} strong text I am taking this Udemy course where it seems to be working fine but on my system, it is not working at all.

Read more here:

Content Attribution

This content was originally published by Sachin Kashyap at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: