使用委托和RxCocoa显示'#selector'的参数是指未向Objective-C公开的实例

问题描述 投票:1回答:1

我希望使用DelegateProxy将此删除与RxCcocoa和RxSwift进行反应。我收到此错误:

'#selector'的参数是指未暴露给Objective-C的实例方法'rangeSeekSlider(_:didChange:maxValue :)'

我正在从这个图书馆转换的代表:https://github.com/WorldDownTown/RangeSeekSlider/blob/master/Sources/RangeSeekSliderDelegate.swift

import CoreGraphics

public protocol RangeSeekSliderDelegate: class {

/// Called when the RangeSeekSlider values are changed
///
/// - Parameters:
///   - slider: RangeSeekSlider
///   - minValue: minimum value
///   - maxValue: maximum value
func rangeSeekSlider(_ slider: RangeSeekSlider, didChange minValue: CGFloat, maxValue: CGFloat)

...
}

这是委托代理

import RxSwift
import RxCocoa
import RangeSeekSlider

final class RxRangeSeekSliderDelegateProxy:
DelegateProxy<RangeSeekSlider, RangeSeekSliderDelegate>,
RangeSeekSliderDelegate,
DelegateProxyType {

init(rangeSeekSlider: RangeSeekSlider) {
    super.init(parentObject: rangeSeekSlider, delegateProxy: RxRangeSeekSliderDelegateProxy.self)
}

static func registerKnownImplementations() {
    register { RxRangeSeekSliderDelegateProxy(rangeSeekSlider: $0) }
}

static func currentDelegate(for object: RangeSeekSlider) -> RangeSeekSliderDelegate? {
    return object.delegate
}

static func setCurrentDelegate(_ delegate: RangeSeekSliderDelegate?, to object: RangeSeekSlider) {
    object.delegate = delegate
}
}

滑块的反应式扩展,这是我得到错误的地方:

import RxSwift
import RxCocoa
import RangeSeekSlider


extension Reactive where Base: RangeSeekSlider {
var delegate: DelegateProxy<RangeSeekSlider, RangeSeekSliderDelegate> {
    return RxRangeSeekSliderDelegateProxy.proxy(for: base)
}

var didChange: Observable<(Bool, Bool)> {
    let source = delegate.methodInvoked(#selector(RangeSeekSliderDelegate.rangeSeekSlider(_:didChange:maxValue:)))
        .map{ (parameters) in
            return (parameters[0] as? Bool ?? false, parameters[1] as? Bool ?? false)
    }
    return source
}

}

ios swift rx-swift
1个回答
2
投票

协议本身需要暴露给Objective-C。

更改

public protocol RangeSeekSliderDelegate: class {

@objc public protocol RangeSeekSliderDelegate {
© www.soinside.com 2019 - 2024. All rights reserved.