How to Detect the Retina Display for macOS in SwiftUI

In Cocoa, you can find out whether or not you have a Retina screen with the backingScaleFactor property like the following.

func getWinFactor() -> CGFloat? {
	if let view = self.view.window {
		let factor = view.backingScaleFactor
		return factor
	} else {
		return nil
	}
}

How could we detect whether or not the application is dealing with a Retina screen in SwiftUI? I thought the displayScale Environment property is the chosen one. But my 27-inch iMac with a Retina display will return the scale as 1.0.

import SwiftUI

struct ContentView: View {
	@Environment(\.displayScale) var displayScale

	var body: some View {
		VStack {
			...
		}
		.onAppear {
			print("display scale: \(displayScale)") // Returning 1.0
		}
	}
}

Do I miss something with this environment guy? Muchos thankos.

For whatever reason, I'm getting the expected "2.0" with my Studio Display.

(There's also pixelLength, which returns the length of one pixel in points.)

How to Detect the Retina Display for macOS in SwiftUI
 
 
Q