Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift RxCocoa:无法调用';绑定&x27;具有类型为';(致:(UITapGestureRecognitor)>;Void)和#x27;_Swift_Rx Swift - Fatal编程技术网

Swift RxCocoa:无法调用';绑定&x27;具有类型为';(致:(UITapGestureRecognitor)>;Void)和#x27;

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

我使用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: @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 tips
event
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(“绑定错误:\(错误)”)
})
}