添加多个代理而不是仅添加一个委托是一项非常常见的任务.假设我们有协议和类:
原文链接:https://www.f2er.com/swift/318738.htmlprotocol ObserverProtocol { ... } class BroadcasterClass { // Error: Type 'ObserverProtocol' does not conform to protocol 'AnyObject' private var _observers = NSHashTable<ObserverProtocol>.weakObjects() }
如果我们试图强制ObserverProtocol符合AnyObject协议,我们将收到另一个错误:
Using ‘ObserverProtocol’ as a concrete type conforming to protocol ‘AnyObject’ is not supported
甚至可以在Swift 3.0中创建一组弱委托吗?