小编mar*_*mas的帖子

Swift Combine 如何跳过一个事件

我在我的应用程序中使用了一个用于日志记录页面的表单,并且在页脚上有一个绑定来显示任何错误,如下所示:

内容视图.Swift :

Form { Section(footer: Text(self.viewModel.errorMessage))
Run Code Online (Sandbox Code Playgroud)

视图模型.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)
}
Run Code Online (Sandbox Code Playgroud)

问题是 viewModel 中的分配是在 init 中执行的,所以当我启动我的应用程序时,即使用户还没有尝试写任何东西,它也会显示消息。

Is there a way to skip first event like in RxSwift where you would just .skip(1) in combine framework?

swift combine

0
推荐指数
1
解决办法
1286
查看次数

标签 统计

combine ×1

swift ×1