【发布时间】:2014-06-05 23:15:48
【问题描述】:
我在玩 Swift。我有一个协议定义为
protocol timerProtocol {
func timerFired()
}
持有对委托的引用的类
class Stopwatch: NSObject {
var delegate: protocol <timerProtocol>
init(delegate: protocol <timerProtocol> ) {
self.delegate = delegate
}
...
}
以及实现协议的类
class StopwatchesTableViewController: UITableViewController, timerProtocol {
func timerFired() {
println("timer");
}
let stopwatch = Stopwatch(delegate: self) // Error here
...
}
我在声明秒表时遇到错误 - “Type 'StopwatchesTableViewController -> () -> StopwatchesTableViewController!'不符合协议'timerProtocol'"
我该如何解决这个问题?
【问题讨论】:
-
您不能将
self引用为实例直到该实例不存在。