0

I would like to use a singleton to manage a NSTimer. This singleton should start/stop a timer and this timer should run a function each time the timer is done.

import Foundation
import CoreData
import UIKit

class TimerManager{

    var delegate: TimerManager?
    var timer: NSTimer?

    static let sharedInstance = TimerManager()

    private init(){
        timer = NSTimer()
    }

    func startTimer(){
        timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("countUp"), userInfo: nil, repeats: true)
    }

    func countUp(){
        print("do something...")
    }

}

But this is makes an error

*** NSForwarding: warning: object 0x7fa04a42c840 of class 'Ttc.TimerManager' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector -[Ttc.TrackingManager countUp]

elyrico
  • 519
  • 6
  • 19
  • if TimerManager is a singleton, shouldn't it be `static let sharedInstance = TimerManager()` instead of `TrackingManager`? – Nimble Feb 10 '16 at 14:51
  • Once you instantiate it the class functions are effectively invisible. – David Hoelzer Feb 10 '16 at 14:51
  • I edited my code. TrackingManager my old Class name. I also remove Class before countUp function but I still have the same error. – elyrico Feb 10 '16 at 14:55
  • 2
    take a look http://stackoverflow.com/questions/24415662/object-x-of-class-y-does-not-implement-methodsignatureforselector-in-swift – Nimble Feb 10 '16 at 14:58
  • thanks @Nimble. I add @ objc before func countUp() and it works... I suppose it is because NSTimer inherits from NSObject – elyrico Feb 10 '16 at 15:06

0 Answers0