watch-os-6

Using environmentObject in watchOS

独自空忆成欢 提交于 2019-12-09 08:28:28
问题 I am trying to use environmentObject in a watchOS6 app to bind my data model to my view. I have created a simple, stand-alone Watch app in Xcode 11. I created a new DataModel class import Combine import Foundation import SwiftUI final class DataModel: BindableObject { let didChange = PassthroughSubject<DataModel,Never>() var aString: String = "" { didSet { didChange.send(self) } } } In my ContentView struct I bind this class using @EnvironmentObject - struct ContentView : View {

Using environmentObject in watchOS

微笑、不失礼 提交于 2019-12-04 00:28:46
I am trying to use environmentObject in a watchOS6 app to bind my data model to my view. I have created a simple, stand-alone Watch app in Xcode 11. I created a new DataModel class import Combine import Foundation import SwiftUI final class DataModel: BindableObject { let didChange = PassthroughSubject<DataModel,Never>() var aString: String = "" { didSet { didChange.send(self) } } } In my ContentView struct I bind this class using @EnvironmentObject - struct ContentView : View { @EnvironmentObject private var dataModel: DataModel var body: some View { Text($dataModel.aString.value) } } Finally