1

I have a timer function that works in the viewcontroller.swift file here:

override func viewDidLoad() {
    super.viewDidLoad()
    //Swift 3 selector syntax
    var timer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(self.update), userInfo: nil, repeats: true)
}

// must be internal or public. 
func update() {
    // Something cool
}

I need to get it to work in my gamescene.swift file. This is what I had that wasn't working:

var currentTimeSeconds = 0

        override public func didMove(to view: SKView) {
                var timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(update), userInfo: nil, repeats: true)
    }
        public func update() {
            currentTimeSeconds = currentTimeSeconds + 1
        }

I keep getting the error "ambiguous use of 'update.'"

Evan
  • 21
  • 1
  • `SKScene` already has an `update()` method. Renaming yours is the easiest solution. – Martin R Apr 10 '17 at 17:42
  • Essentially a duplicate of http://stackoverflow.com/questions/35658334/how-do-i-resolve-ambiguous-use-of-compile-error-with-swift-selector-syntax (I assume) – Martin R Apr 10 '17 at 17:45

0 Answers0