Updating a @Published variable based on changes in an observed variable
问题 I have an AppState that can be observed: class AppState: ObservableObject { private init() {} static let shared = AppState() @Published fileprivate(set) var isLoggedIn = false } A View Model should decide which view to show based on the state ( isLoggedIn ): class HostViewModel: ObservableObject, Identifiable { enum DisplayableContent { case welcome case navigationWrapper } @Published var containedView: DisplayableContent = AppState.shared.isLoggedIn ? .navigationWrapper : .welcome } In the