How to use BindableObjects (EnviromentObject)?

前端 未结 2 1174
礼貌的吻别
礼貌的吻别 2021-01-24 03:26

Im using the new SwiftUI. I have a UserUpdate class which is a Bindable Object and I want to modify these variables and automatically Update the UI.

2条回答
  •  面向向阳花
    2021-01-24 03:36

    I found out that I had to call the method from my UI to get it working so its on the same stream.

    For example by this:

    struct ContentView : View {
    @EnvironmentObject var networkManager: NetworkManager
    
    var body: some View {
        VStack {
            Button(action: {
                self.networkManager.getAllCourses()
            }, label: {
                Text("Get All Courses")
            })
    
            List(networkManager.courses.identified(by: \.name)) {
                Text($0.name)
            }
        }
    }
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题