gpt4 book ai didi

ios - RxSwift : Error adding RX bind to UITextField: Value of type 'Binder' has no member 'debounce'

转载 作者:行者123 更新时间:2023-11-29 05:16:35 25 4
gpt4 key购买 nike

我尝试在 UITextField 中添加延迟,但出现以下错误:

Property 'text' requires that 'UITextField' inherit from 'UILabel'
Value of type 'Binder<String?>' has no member 'debounce'

这是我的实现:

   func bind() {
(myTextField.rx.text.debounce(0.5, scheduler: MainScheduler.instance) as AnyObject)
.map {
if $0 == ""{
return "Type your name bellow"
}else {
return "Hello, \($0 ?? "")."
}
}
.bind(to: myLbl.rx.text)
.disposed(by: disposeBag)
}

你们中有人知道我为什么会收到此错误吗?

非常感谢您的帮助。

最佳答案

myTextField.rx.textControlProperty<String?> ,有时长链可能会让 Swift 编译器难以区分您想要完成的任务。最好声明您的意图并将长链拆分为变量:

func bind() {
// The way you wanted to do it
let property: ControlProperty<String> = _textField.rx.text
.orEmpty
// Your map here

property
.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
.bind(to: _descriptionLabel.rx.text)
.disposed(by: _disposeBag)

// Driver is a bit better for UI
let text: Driver<String> = _textField.rx.text
.orEmpty
// Insert your map here
.asDriver()

text
.debounce(.milliseconds(500))
.drive(_descriptionLabel.rx.text)
.disposed(by: _disposeBag)
}

附言使用Driver将为您节省一些 UI 打字时间并使其更加清晰。

关于ios - RxSwift : Error adding RX bind to UITextField: Value of type 'Binder<String?>' has no member 'debounce' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59130647/

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