Reputation: 275
I have a file called Util.swift with the following
class foo: NSObject {
func sayHello() {
print("hello")
}
}
var globalTimer = NSTimer()
func startTheTimer() {
globalTimer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: foo.self, selector: Selector("sayHello"), userInfo: nil, repeats: true)
}
When I call startTheTimer() in the viewDidLoad of any of my viewControllers, I get an error saying "unrecognized selector sent to class". I don't know what I have done wrong here.
Upvotes: 2
Views: 417
Reputation: 3508
I have updated your code here:
class foo: NSObject {
class func sayHello() {
print("hello")
}
}
var globalTimer = NSTimer()
func startTheTimer() {
globalTimer = NSTimer.scheduledTimerWithTimeInterval(2.0, target: foo.self, selector: Selector("sayHello"), userInfo: nil, repeats: true)
}
Upvotes: 0
Reputation: 506
class func sayHello() {
print("hello")
}
make this a class method please.
Upvotes: 2