简体   繁体   English

选择器表达式类型在没有更多上下文的情况下不明确

[英]Selector type of expression is ambiguous without more context

I'm trying to get ARSessionDelegate method using selector, but im getting this error: Type of expression is ambiguous without more context我正在尝试使用选择器获取 ARSessionDelegate 方法,但我收到此错误: Type of expression is ambiguous without more context

There is mine code:有我的代码:

#selector(ARSessionDelegate.session(_:didUpdate:) as ((ARSessionDelegate) -> (ARSession, ARFrame) -> Void)) 

That's how this method looks like:这就是这个方法的样子:

public protocol ARSessionDelegate : ARSessionObserver {
    optional func session(_ session: ARSession, didUpdate frame: ARFrame)
}

And also, I am trying to make an rx extension for the ARKit session using this answer, but im not sure it's caused the problem.而且,我正在尝试使用答案为 ARKit session 进行 rx 扩展,但我不确定它是否导致了问题。

Because there are multiple methods with the same selector name, you are forced to implement the method in the delegate and forward the calls using a subject.因为有多个方法具有相同的选择器名称,所以您被迫在委托中实现该方法并使用主题转发调用。 Like this:像这样:

extension ARSession: HasDelegate { }

extension Reactive where Base: ARSession {
    var delegate: ARSessionDelegateProxy {
        return ARSessionDelegateProxy.proxy(for: base)
    }

    var didUpdate: Observable<ARFrame> {
        return delegate.didUpdate.asObservable()
    }
}

final class ARSessionDelegateProxy
: DelegateProxy<ARSession, ARSessionDelegate>
, DelegateProxyType
, ARSessionDelegate {
    init(parentObject: ARSession) {
        super.init(
            parentObject: parentObject,
            delegateProxy: ARSessionDelegateProxy.self
        )
    }

    deinit {
        didUpdate.onCompleted()
    }

    public static func registerKnownImplementations() {
        self.register { ARSessionDelegateProxy(parentObject: $0) }
    }

    func session(_ session: ARSession, didUpdate frame: ARFrame) {
        didUpdate.onNext(frame)
    }

    fileprivate let didUpdate = PublishSubject<ARFrame>()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM