【发布时间】:2020-09-19 20:56:39
【问题描述】:
我在我的应用程序中使用了一个日志页面的表单,并且我在页脚上绑定了显示任何错误,如下所示:
ContentView.Swift:
Form { Section(footer: Text(self.viewModel.errorMessage))
ViewModel.swift
init() {
self.isCurrentNameValid
.receive(on: RunLoop.main)
.map { $0 ? "" : "username must at least have 5 characters" }
.assign(to: \.errorMessage, on: self)
.store(in: &cancelSet)
}
问题是 viewModel 中的分配是在 init 中执行的,所以当我启动我的应用程序时,即使用户还没有尝试写任何东西,它也会显示消息。
有没有办法像在 RxSwift 中那样跳过第一个事件,而在组合框架中只需 .skip(1)?
【问题讨论】: