这是我的基本内容视图
struct ContentView: View
{
@ObservedObject var model = Model()
init(model: Model)
{
self.model = model
}
// How to observe model.networkInfo's value over here and run "runThis()" whenever the value changes?
func runThis()
{
// Function that I want to run
}
var body: some View
{
VStack
{
// Some widgets here
}
}
}
}
这是我的模型
class Model: ObservableObject
{
@Published var networkInfo: String
{
didSet
{
// How to access ContentView and run "runThis" method from there?
}
}
}
我不确定它是否可以访问?或者如果我可以从 View 观察 ObservableObject 的变化并运行任何方法?
提前致谢!