【发布时间】:2021-05-15 21:27:09
【问题描述】:
我想监听 $email 和 $password 的更改,然后将结果存储在 signInDisabled 中,但我不确定如何监听两者的更改。
@Published var email = ""
@Published var password = ""
var signInDisabled = true
var session : SessionListenerProtocol
private var cancellables = Set<AnyCancellable>()
init(){
// ???
$email, $password { email, password in
email == "" || password == ""
}
.assign(to: \.signInDisabled, on: self)
.store(in: &cancellables)
}
【问题讨论】:
-
取决于你的意思。您可以使用merge、zip 或combineLatest。请参阅我的stackoverflow.com/a/67099668/341994 进行一些讨论,并在线预订以了解详细信息。 apeth.com/UnderstandingCombine/operators/operatorsJoiners/…
-
@matt 我试过 $email.zip($password) { email, password 但是这个功能只在修改邮箱时触发,不是密码。