【发布时间】:2017-06-11 08:45:21
【问题描述】:
添加多个代表而不是只添加一个代表是一项非常常见的任务。假设我们有协议和一个类:
protocol ObserverProtocol
{
...
}
class BroadcasterClass
{
// Error: Type 'ObserverProtocol' does not conform to protocol 'AnyObject'
private var _observers = NSHashTable<ObserverProtocol>.weakObjects()
}
如果我们试图强制ObserverProtocol 符合AnyObject 协议,我们会得到另一个错误:
不支持使用 'ObserverProtocol' 作为符合协议 'AnyObject' 的具体类型
是否可以在 Swift 3.0 中创建一组弱委托?
【问题讨论】:
标签: swift delegates swift3 observer-pattern