无法推断通用参数 'A'(Swift 4,从 Swift 2 迁移的 Bond 和 ReactiveKit 框架)

Generic parameter 'A' could not be inferred (Swift 4, Bond and ReactiveKit frameworks migrating from Swift 2)

伙计们!我正在尝试从 Swift 2 迁移到 Swift 4。项目正在使用 Bond 和 ReactiveKit 框架。我有 UISearchBar 的扩展。所以我在从这里迁移时遇到了问题:

import UIKit
import Bond
import ReactiveKit

public extension UISearchBar {
    public var bnd_delegate: ProtocolProxy {
        return protocolProxy(for: UISearchBarDelegate.self, setter: NSSelectorFromString("setDelegate:"))
    }
}

public extension UISearchBar {

    public var bnd_text: DynamicSubject<UISearchBar, String?> {
        let dispatcher: (PublishSubject<Void, NoError>, UISearchBar, String) -> Void = { _ in }
        let selector = #selector(UISearchBarDelegate.searchBar(_:textDidChange:))

    return DynamicSubject(
        target: self,
        signal: bnd_delegate.signal(for: selector, dispatch: dispatcher),
        get: { [=13=].text },
        set: { [=13=].text =  }
        )
    }
}

我已经做了一些修改,变成了这段代码:

import UIKit
import Bond
import ReactiveKit

public extension UISearchBar {
    public var delegate: ProtocolProxy {
    return protocolProxy(for: UISearchBarDelegate.self, setter: NSSelectorFromString("setDelegate:"))
}

public var text: DynamicSubject<String?> {
    let dispatcher: (PublishSubject<Void, NoError>, UISearchBar, String) -> Void = { _,_,_   in }
    let selector = #selector(UISearchBarDelegate.searchBar(_:textDidChange:))

    return DynamicSubject<String?>(
        target: self,
        signal: delegate.signal(for: selector, dispatch: dispatcher),
        get: { [=14=].text },
        set: { [=14=].text =  }
        )
    }
}

目前我的 DynamicSubject 有错误: Generic parameter 'A' could not be inferred. And it is strange, because I checked what does my 'dispatch' takes as a value: (for: Selector, dispatch: (PublishSubject< S, NoError>, A, B) -> R).

我尝试使用多个变量进行调度,但一无所获。在我看来 Xcode 无法识别在 PublishSubject 参数之后开始的任何变量。

我想知道我做错了什么。

如果您曾经从旧版本的 ReactiveKit/Bond 实现的语法迁移,这里是如何为您的 UIKit Reactive Extensions 迁移:

import UIKit
import Bond
import ReactiveKit

extension ReactiveExtensions where Base: UISearchBar {

    var delegate: ProtocolProxy {
        return base.protocolProxy(for: UISearchBarDelegate.self, setter: NSSelectorFromString("setDelegate:"))
    }

    var text: DynamicSubject<String?> {

        let selector = #selector(UISearchBarDelegate.searchBar(_:textDidChange:))
        let textChanged = delegate.signal(for: selector) { (subj: SafePublishSubject<Void>, _: UISearchBar, _: NSString) in
            subj.next(())
        }

        return dynamicSubject(
            signal: textChanged,
            get: { [=10=].text },
            set: { [=10=].text =  }
        )
    }
}

extension UISearchBar: BindableProtocol {

    public func bind(signal: SafeSignal<String?>) -> Disposable {
        return reactive.text.bind(signal: signal)
    }
}