I created a minimal project in Xcode 15.3 to reproduce the issue (run on MacOS 14.7).
When compiled with Xcode 15.3, the toggle switches from light to dark mode.
When compiled with Xcode 16 (16.0 or 16.1ß3), the toggle has no effect.
I attached the complete project to FB report.
import SwiftUI
@main
struct DarkModeTest_MacApp: App {
@AppStorage("isDarkMode") private var isDarkMode = false
var body: some Scene {
WindowGroup {
ContentView()
.frame(
minWidth: 300, maxWidth: .infinity,
minHeight: 200, maxHeight: .infinity)
.preferredColorScheme(isDarkMode ? .dark : .light)
}
.windowResizability(.contentSize)
}
}
import SwiftUI
struct ContentView: View {
@AppStorage("isDarkMode") private var isDarkMode = false
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button(action: {
isDarkMode.toggle()
}) {
Text("Toggle")
}
}
.padding()
}
}
#Preview {
ContentView()
}
Additional information: It works on iPad (simulator).
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: