我希望此删除操作使用DelegateProxy与RxCcocoa和RxSwift反应。我收到此错误:
“#selector”的参数引用实例方法 未暴露给的'rangeSeekSlider(_:didChange:maxValue :)' Objective-C
我正在从此库转换的委托: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
}
}
答案 0 :(得分:2)
本身协议需要暴露给Objective-C。
更改
public protocol RangeSeekSliderDelegate: class {
到
@objc public protocol RangeSeekSliderDelegate {