Skip to content

Instantly share code, notes, and snippets.

@christianselig
Created May 19, 2024 20:37
Show Gist options
  • Save christianselig/d88b1a4d1989b973689ae62d4691162f to your computer and use it in GitHub Desktop.
Save christianselig/d88b1a4d1989b973689ae62d4691162f to your computer and use it in GitHub Desktop.
import SwiftUI
@main
struct WindowPresentationFunApp: App {
@State var appState = AppState()
var body: some Scene {
WindowGroup {
RootView(appState: appState)
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
appState.show = true
}
}
}
}
}
struct RootView: View {
var appState: AppState
var body: some View {
ZStack {
SpecialView()
if appState.show {
Text("Some cool text")
}
}
}
}
struct SpecialView: View {
@State var viewModel = ViewModel()
var body: some View {
Text("Special stuff")
}
}
@Observable class AppState {
var show: Bool = false
}
@Observable class ViewModel {
init() {
print("✅ View model was inited")
}
deinit {
print("❌ View model was deinited")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment