For Mac Catalyst, is there an approved method of setting the window's aspect ratio?

I'm currently using this hack to get a reference to the underlying NSWindow:
Code Block
func nsWindow(from window: UIWindow) -> AnyObject? {
    guard let nsWindows = NSClassFromString("NSApplication")?.value(forKeyPath: "sharedApplication.windows") as? [AnyObject] else { return nil }
    for nsWindow in nsWindows {
        let uiWindows = nsWindow.value(forKeyPath: "uiWindows") as? [UIWindow] ?? []
        if uiWindows.contains(window) { return nsWindow }
    }
    return nil
}

Then this to set the aspect ratio:
Code Block
 nsw.setValue(CGSize(width: 1.5, height: 1.0), forKey: "aspectRatio")

Which gives the following log output:

WARNING: SPI usage of '-[UINSWindow uiWindows]' is being shimmed. This will break in the future. Please file a radar requesting API for what you are trying to do.

Before filing a feedback request, is there a more robust/approved method of doing this?




Post not yet marked as solved Up vote post of 3no Down vote post of 3no
1.1k views
Add a Comment