Optimal Way of Getting Screen Resolution Using SwiftUI

Hi all, I am looking for a futureproof way of getting the Screen Resolution of my display device using SwiftUI in MacOS. I understand that it can't really be done to the fullest extent, meaning that the closest API we have is the GeometeryProxy and that would only result in the resolution of the parent view, which in the MacOS case would not give us the display's screen resolution. The only viable option I am left with is NSScreen.frame.

However, my issue here is that it seems like Apple is moving towards SwiftUI aggressively, and in order to futureproof my application I need to not rely on AppKit methods as much. Hence, my question: Is there a way to get the Screen Resolution of a Display using SwiftUI that Apple itself recommends? If not, then can I rely safely on NSScreen's frame API?

I won't recommend you use NSScreen.frame because it gives you information on the available displays and not the scene or in cases where your app supports multiple scene, multitasking or resizing.

For SwiftUI, use GeometryReader and for UIkit/AppKit use UIWindowScene.coordinateSpace.bound or UIWindow bounds or frame, to get the location and size in its coordinate space.

I understand that using GeometryReader in SwiftUI or accessing an NSWindow’s bounds/frame in AppKit is ideal for obtaining the dimensions of a specific window or view. However, my objective is different — I need to determine the resolution of the entire, usable screen available on macOS. In other words, I’m looking to retrieve the full physical display size (or the “usable” portion, accounting for elements like the menu bar or dock) rather than just the size of the active window.

Could Apple recommend a futureproof way to obtain this global screen resolution? Or, if no alternative exists, is it acceptable to continue using NSScreen.frame (or NSScreen.visibleFrame for usable space) despite its drawbacks in multi-window or multitasking scenarios?

Optimal Way of Getting Screen Resolution Using SwiftUI
 
 
Q