不能在 DelegateProxyType (rxSwift) 中使用 proxyForObject 函数 [英] Can not use proxyForObject function in DelegateProxyType (rxSwift)

查看:49
本文介绍了不能在 DelegateProxyType (rxSwift) 中使用 proxyForObject 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将 SRWebSocket 的委托迁移到 observable.这是我的 RxSocketManagerDelegateProxy.swift:

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)
}

// ...

}

问题出在 proxyForObject 函数中.它不像上面那样编译.我收到警告静态成员 'proxyForObject' 不能用于类型为 'DelegateProxyType.Protocol' 的实例".

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'".

当我尝试像这样使用 proxyForObjectFunction 时(虽然它已被弃用):

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

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

我收到消息断言失败::文件/Users/Agentum/Documents/Xcode/Telemetry/Pods/RxCocoa/RxCocoa/Common/DelegateProxyType.swift".

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

我应该如何使用 proxyForObject() 函数来正确迁移委托?

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

推荐答案

您应该在 RxSocketManagerDelegateProxy 上调用 proxyForObject,而不是 DelegateProxyType.

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)`
    }
}

这篇关于不能在 DelegateProxyType (rxSwift) 中使用 proxyForObject 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆