Using availablity checks with new .defaultWindowPlacement API

How can I use availability checks with the new defaultWindowPlacement API so I can ensure visionOS 2 users get the correct window placement and visionOS 1 users fall back to the old window placement mechanism?

I have tried using if #available and @available in different ways, but end up with either an error that says control flow statements aren't allowed in SceneBuilders or that the return type of the two branches of my control flow statement do not match if I omit the SceneBuilder property.

An example of how to use .defaultWindowPlacement with visionOS 1 support would be nice. Thank you!

Answered by DependentlyTyped in 793001022

It turns out you can use if #available checks in scenes, you just can't specify an else block with it.

Accepted Answer

It turns out you can use if #available checks in scenes, you just can't specify an else block with it.

As I had the same pattern to solve, I found out the following gist:

https://gist.github.com/drewolbrich/15de5f1cac0163ad80150ad81a291776

Looks like it solves the problem.

Using availablity checks with new .defaultWindowPlacement API
 
 
Q