How to exclude unavailable classes from compilation based on the target OS

I have a class that's unavailable on iOS, so I annotated it with @available, but the compiler still complains that some symbol is not available on iOS. I even added the annotation to the method itself, but no luck.

How can I fix the error without adding the ugly "#if os(macOS)" around the missing symbol?

@available(iOS, unavailable)
class AboutDelegate {

	// @available(iOS, unavailable)
	func show() {
		var window: UIWindowScene
		//...
		window?.windowingBehaviors?.isMiniaturizable = false // Error: 'windowingBehaviors' is only available in iOS 16.0 or newer
	}
}

Per the documentation, windowingBehaviours is only unavailable on macOS: windowingBehaviors | Apple Developer Documentation. It seems like you've got the condition backwards, and should be marking the type unavailable on macOS, not on iOS.

I'm actually compiling it for macCatalyst, where the symbol is available, and I've solved it using '#if targetEnvironment(macCatalyst)'. I've wrote "#if os(macOS) for brevity. But that's just an example, I basically want to make some class unavailable on some platform, because it uses symbols not available on that platform.

I have update the example below. It won't compile on iOS.

@available(iOS, unavailable)
class AboutDelegate {

	// @available(iOS, unavailable)
	func show() {
		var window: UIWindowScene
		//...
		if #available(macCatalyst 16.0, *) {
			window.windowingBehaviors?.isMiniaturizable = false // Error: 'windowingBehaviors' is only available in iOS 16.0 or newer
		}
	}
}