admin管理员组文章数量:1336367
I have a view model, that has a network service that returns us a Combine publisher. The VM reacts to this publisher by updating its state. And the UIViewController
would then update based on the VM state change. This was the setup for UIKit
.
Now I am introducing SwiftUI
views. I am new to swift UI and not sure how to use the VM's state publisher in SwiftUI.
The VM's state is a CurrentValueSubject
right now.
Thanks in advance.
I have a view model, that has a network service that returns us a Combine publisher. The VM reacts to this publisher by updating its state. And the UIViewController
would then update based on the VM state change. This was the setup for UIKit
.
Now I am introducing SwiftUI
views. I am new to swift UI and not sure how to use the VM's state publisher in SwiftUI.
The VM's state is a CurrentValueSubject
right now.
Thanks in advance.
Share Improve this question asked Nov 19, 2024 at 23:57 iOSeriOSer 2842 silver badges14 bronze badges 6 | Show 1 more comment1 Answer
Reset to default -1SwiftUI uses the @StateObject or @ObservedObject property wrapper to observe changes in the ViewModel. To enable this, conform your ViewModel to ObservableObject and use a @Published property to represent the state.
Since you already have a CurrentValueSubject in your ViewModel, you can connect it to a @Published property.
本文标签: mvvmHow do I refresh my SwiftUI to changes in my view modelStack Overflow
版权声明:本文标题:mvvm - How do I refresh my SwiftUI to changes in my view model? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742390034a2465803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
ObservabeObject
@Published
andassign
fromCombine
– lorem ipsum Commented Nov 20, 2024 at 1:22