Created
May 19, 2024 20:37
-
-
Save christianselig/d88b1a4d1989b973689ae62d4691162f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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