Can not use proxyForObject function in DelegateProxyType (rxSwift)

独自空忆成欢 提交于 2019-12-24 07:26:05

问题


I try to migrate delegate of SRWebSocket to observable. This is my 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)
}

// ...

}

The problem is in proxyForObject function. It is not compiled like above. I get warning "Static member 'proxyForObject' cannot be used on instance of type 'DelegateProxyType.Protocol'".

When I try to use proxyForObjectFunction like this (though it is deprecated):

public var rx_delegate: DelegateProxy{
    return proxyForObject(RxSocketManagerDelegateProxy.self, self)
}

I get message "assertion failed: : file /Users/Agentum/Documents/Xcode/Telemetry/Pods/RxCocoa/RxCocoa/Common/DelegateProxyType.swift".

How should I use proxyForObject() function in order to migrate the delegate correct?


回答1:


You should be calling proxyForObject on RxSocketManagerDelegateProxy, not DelegateProxyType.

extension SRWebSocket {
    public var rx_delegate: DelegateProxy {
        return RxSocketManagerDelegateProxy.proxyForObject(self)
        // instead of: `return DelegateProxyType.proxyForObject(self)`
    }
}


来源:https://stackoverflow.com/questions/38325626/can-not-use-proxyforobject-function-in-delegateproxytype-rxswift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!