最佳答案
我有一个类 Person,它被实例化了多次。每个人都有自己的计时器。在我的 init
对于 Person
我调用 startTimer()
。
class Person {
var timer = NSTimer()
func startTimer() {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("timerTick"), userInfo: nil, repeats: true)
}
func timerTick() {
angerLevel++
println("Angry! \(angerLevel)")
}
...
...
}
所以我可能在一个 Person[]
数组中有3个 Person 实例。我得到一个错误:
2014-06-25 13:57:14.956 ThisProgram[3842:148856] *** NSForwarding: warning: object 0x113760048 of class '_TtC11ThisProgram6Person' does not implement methodSignatureForSelector: -- trouble ahead
我在其他地方读到,我应该从 NSObject
继承,但这是在斯威夫特,而不是 Obj-C。这个函数在类中,所以我不知道该怎么做。