import Combine
class ModelData: ObservableObject {
@Published var nestedObservableObject = NestedObservableObject()
init(database: AppDatabase) {
anyCancellable = nestedObservableObject.objectWillChange.sink { [weak self] (_) in
self?.objectWillChange.send()
}
// this does not work, cannot print anything when stringIWant changes
var myCancellable = nestedObservableObject.$aStruct.sink { aStruct in
print("myCancellable observed changes: \(aStruct.stringIWant)")
}
}
class NestedObservableObject: ObservableObject {
@Published var aStruct: aStruct?
}
struct PTTelemetryEvent {
var stringIWant: String = ""
}
Hey everyone, what would be the proper way to use combine when dealing with the nested ObservableObject?