2024-12-06
改变后需要重新渲染的变量使用@state标注,如果是object则用@StateObject。
@State var showingSettings = false
@StateObject var viewModel = ContentViewModel()
class ContentViewModel: ObservableObject {
}
class ContentViewModel: ObservableObject {
@Published var title = ""
}