不能在 DelegateProxyType (rxSwift) 中使用 proxyForObject 函数
Can not use proxyForObject function in DelegateProxyType (rxSwift)
我尝试将 SRWebSocket 的委托迁移到可观察的。这是我的 RxSocketManagerDelegateProxy.swift:
class RxSocketManagerDelegateProxy: DelegateProxy, DelegateProxyType{
static func currentDelegateFor(object: AnyObject) -> AnyObject?{
let socket: SRWebSocket = object as! SRWebSocket
return socket.delegate
}
static func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) {
let socket: SRWebSocket = object as! SRWebSocket
socket.delegate = delegate as? SRWebSocketDelegate
}
}
extension SRWebSocket{
public var rx_delegate: DelegateProxy{
return DelegateProxyType.proxyForObject(self)
}
// ...
}
问题出在 proxyForObject 函数中。它不是像上面那样编译的。我收到警告 "Static member 'proxyForObject' cannot be used on instance of type 'DelegateProxyType.Protocol'"。
当我尝试像这样使用 proxyForObjectFunction 时(虽然它已被弃用):
public var rx_delegate: DelegateProxy{
return proxyForObject(RxSocketManagerDelegateProxy.self, self)
}
我收到消息 "assertion failed: : file /Users/Agentum/Documents/Xcode/Telemetry/Pods/RxCocoa/RxCocoa/Common/DelegateProxyType.swift"。
我应该如何使用 proxyForObject() 函数才能正确迁移委托?
您应该在 RxSocketManagerDelegateProxy
上呼叫 proxyForObject
,而不是 DelegateProxyType
。
extension SRWebSocket {
public var rx_delegate: DelegateProxy {
return RxSocketManagerDelegateProxy.proxyForObject(self)
// instead of: `return DelegateProxyType.proxyForObject(self)`
}
}
我尝试将 SRWebSocket 的委托迁移到可观察的。这是我的 RxSocketManagerDelegateProxy.swift:
class RxSocketManagerDelegateProxy: DelegateProxy, DelegateProxyType{
static func currentDelegateFor(object: AnyObject) -> AnyObject?{
let socket: SRWebSocket = object as! SRWebSocket
return socket.delegate
}
static func setCurrentDelegate(delegate: AnyObject?, toObject object: AnyObject) {
let socket: SRWebSocket = object as! SRWebSocket
socket.delegate = delegate as? SRWebSocketDelegate
}
}
extension SRWebSocket{
public var rx_delegate: DelegateProxy{
return DelegateProxyType.proxyForObject(self)
}
// ...
}
问题出在 proxyForObject 函数中。它不是像上面那样编译的。我收到警告 "Static member 'proxyForObject' cannot be used on instance of type 'DelegateProxyType.Protocol'"。
当我尝试像这样使用 proxyForObjectFunction 时(虽然它已被弃用):
public var rx_delegate: DelegateProxy{
return proxyForObject(RxSocketManagerDelegateProxy.self, self)
}
我收到消息 "assertion failed: : file /Users/Agentum/Documents/Xcode/Telemetry/Pods/RxCocoa/RxCocoa/Common/DelegateProxyType.swift"。
我应该如何使用 proxyForObject() 函数才能正确迁移委托?
您应该在 RxSocketManagerDelegateProxy
上呼叫 proxyForObject
,而不是 DelegateProxyType
。
extension SRWebSocket {
public var rx_delegate: DelegateProxy {
return RxSocketManagerDelegateProxy.proxyForObject(self)
// instead of: `return DelegateProxyType.proxyForObject(self)`
}
}