Fixed SwiftUI window sizes in macOS with Xcode 14 and Ventura for macOS 11/12 targets

I have a project that requires a fixed window size. In previous versions of Xcode when I compile the project with the following :

struct MyApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .frame(width: 800, height: 600)
        }
    }
}

It will result in a window with a fixed size of 800x600 (i.e. the window inherits the fixed content size)

With Xcode 14 and macOS Ventura, this is no longer the case. The above code compiles but now the window is resizable, with the content inhabiting an 800x600 area.

In Ventura there is the   .windowResizability(.contentSize) property but this is macOS 13 only. I need my app to be able to support macOS 11 and 12 and now the window behaviour is broken with the latest Xcode.

Is there any way to get around this that doesn't involve running a seperate macOS 12/Xcode 13 environment?

Accepted Reply

You can make the .windowResizability(.contentSize) scene modifier conditional like so:

extension Scene {
    func windowResizabilityContentSize() -> some Scene {
        if #available(macOS 13.0, *) {
            return windowResizability(.contentSize)
        } else {
            return self
        }
    }
}

And then use it on WindowGroup this way:

WindowGroup {
    ...
}
.windowResizabilityContentSize()
  • That's perfect, thank you 🙂

  • But this answer is not what he is looking for! He already explained the issue and also gave the needed codes, you just copy and paste the code from question! He is looking make the same thing works for macOS 11 or macOS 12.

  • This worked beautifully, thank you!

Replies

You can make the .windowResizability(.contentSize) scene modifier conditional like so:

extension Scene {
    func windowResizabilityContentSize() -> some Scene {
        if #available(macOS 13.0, *) {
            return windowResizability(.contentSize)
        } else {
            return self
        }
    }
}

And then use it on WindowGroup this way:

WindowGroup {
    ...
}
.windowResizabilityContentSize()
  • That's perfect, thank you 🙂

  • But this answer is not what he is looking for! He already explained the issue and also gave the needed codes, you just copy and paste the code from question! He is looking make the same thing works for macOS 11 or macOS 12.

  • This worked beautifully, thank you!

You rock - have been looking for this for way too long ... .windowResizability(.contentSize) fixed my issues !

+1 for those comments that "windowResizability" doesn't answer the question. The question still stands: How can a window be specified to be NOT resizable in macOS 11 and 12 ?