gpt4 book ai didi

swift - RxCocoa : Cannot invoke 'bind' with an argument list of type '(to: (UITapGestureRecognizer) -> Void)'

转载 作者:行者123 更新时间:2023-11-28 13:24:20 30 4
gpt4 key购买 nike

我使用 RxCocoa,我有这样的代码,

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: (UITapGestureRecognizer) -> Void)'

我试试

 func debug( _ event: @escaping (UITapGestureRecognizer) -> Void){

Xcode 报告:

 Cannot invoke 'bind' with an argument list of type '(to: @escaping (UITapGestureRecognizer) -> Void)'

重要的是什么? Rx 命名空间?

当我在前者输入event时,Xcode提示eventUITapGestureRecognizer

111

最佳答案

我认为bind(onNext: @escaping (E) -> Void)是你要找的,而不是bind<O: ObserverType>(to observer: O) .

比较实现:

public func bind<O: ObserverType>(to observer: O) -> Disposable where O.E == E {
return self.subscribe(observer)
}

public func bind(onNext: @escaping (E) -> Void) -> Disposable {
return subscribe(onNext: onNext, onError: { error in
rxFatalErrorInDebug("Binding error: \(error)")
})
}

关于swift - RxCocoa : Cannot invoke 'bind' with an argument list of type '(to: (UITapGestureRecognizer) -> Void)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58643150/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com