I'm using Xcode 14.1 and created a new macOS 13 project. Before I build/run the project, I added a .defaultSize
to the window group. But when I run the project for the first time, the window size does not adhere to the default size. Is there something else needed to define a default window size?
Here is the ContentView.swift
file:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
}
.padding()
}
}
Here is the ExampleApp.swift
file:
import SwiftUI
@main
struct WindowDefaultSizeApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.defaultSize(width: 300, height: 200)
}
}
It does work, but only if you haven't run the app previously, such that the system "remembers" a non-default size that was used then, or if you manage to reset that memory.
There may be a simpler way to do that, but so far the only reliable way I've found is to:
- delete the reference to my app in
~/Library/Application\ Support/com.apple.windowmanager/state.plist
and resave it - delete my app's folder in
~/Library/Containers/
(that's for a sandboxed app, it may otherwise be underPreferences
) - empty the trash
- restart the Mac
Also, so far I've only tested this with the Window scene rather than WindowGroup. But it was apparently not working with Window either till I managed to clear the previous non-default size using the steps above.