I worked on an app using SwiftUI and Combine framework. Then I used @Published
property wrapper to publish a stream data from a property in a ViewModel class.
By the way when I assign a new value to the property and it doesn’t send a callback to the counterpart SwiftUI view. Then I looked through a similar question in the stack overflow.
Then I followed the answer. But it doesn’t work in my case. So I declared objectWillChange
in the subclass and now it works.
I think that SwiftUI and Combine framework are not stable yet. So you might have this kind of issue.
// ViewModel
var objectWillChange = PassthroughSubject<Void, Never>()
var value: String = "Select" {
willSet {
self.objectWillChange.send()
}
}
// View
var body: some view {
Text(self.viewModel.value)
}
0 κ°μ λκΈ:
Post a Comment