Perhaps I'm using this wrong, but why does the following code not work?
import SwiftUI
import KeyboardShortcuts
@main
struct TestAppApp: App {
@State var isUnicornMode: Bool = false;
init() {
KeyboardShortcuts.onKeyDown(for: .toggleUnicornMode) { [self] in
isUnicornMode.toggle();
print("Unicorn \(isUnicornMode)")
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The print statement is always false.
When I use the @MainActor AppState: ObservableObject it works. I'm new to swift programming, but why does the variable in my example not change? Setting = true directly also does not work.
Perhaps I'm using this wrong, but why does the following code not work?
The print statement is always false. When I use the
@MainActor AppState: ObservableObject
it works. I'm new to swift programming, but why does the variable in my example not change? Setting= true
directly also does not work.