Swift RxCocoa:无法调用';绑定&x27;具有类型为';(致:(UITapGestureRecognitor)>;Void)和#x27;
我使用RxCocoa,我有这样的代码Swift RxCocoa:无法调用';绑定&x27;具有类型为';(致:(UITapGestureRecognitor)>;Void)和#x27;,swift,rx-swift,Swift,Rx Swift,我使用RxCocoa,我有这样的代码 func debug(){ isUserInteractionEnabled = true let tap = UITapGestureRecognizer() tap.numberOfTapsRequired = 2 addGestureRecognizer(tap) tap.rx.event.bind { (event) in if self.p
func debug(){
isUserInteractionEnabled = true
let tap = UITapGestureRecognizer()
tap.numberOfTapsRequired = 2
addGestureRecognizer(tap)
tap.rx.event.bind { (event) in
if self.phone.text == Phone.one{
self.phone.text = Phone.two
}
else{
self.phone.text = Phone.one
}
self.verification.text = ""
}.disposed(by: rx.disposeBag)
}
我想做一些封装,将上面的内容转换为:
func debug( _ event: (UITapGestureRecognizer) -> Void){
isUserInteractionEnabled = true
let tap = UITapGestureRecognizer()
tap.numberOfTapsRequired = 2
addGestureRecognizer(tap)
tap.rx.event.bind(to: event).disposed(by: rx.disposeBag)
}
Xcode报告:
Cannot invoke 'bind' with an argument list of type '(to: @escaping (UITapGestureRecognizer) -> Void)'
无法使用类型为“(to:(UITapGestureRecognizer)->Void)”的参数列表调用“bind”
我试着
func debug( _ event: @escaping (UITapGestureRecognizer) -> Void){
Xcode报告:
Cannot invoke 'bind' with an argument list of type '(to: @escaping (UITapGestureRecognizer) -> Void)'
什么重要?接收名称空间? 当我在前者中键入
event
时,Xcode tipsevent
是uitappesturerecognizer
我认为bind(onNext:@escaping(E)->Void)
是你想要的,而不是bind(to observer:O)
比较实现:
public func bind(到观察者:O)->其中O.E==E{
返回self.subscribe(观察者)
}
公共函数绑定(onNext:@escaping(E)->Void)->一次性{
返回订阅(onNext:onNext,onError:{中有错误
RXFataErrorIndebug(“绑定错误:\(错误)”)
})
}