NSView.clipsToBounds not available

Xcode 15 and Sonoma expose the property NSView.clipsToBounds. On Sonoma I need to set this property to TRUE and this is working well.

However, for reasons, I also need to compile my macOS project with Xcode 13 and Xcode 14. I am having difficulty figuring out the Swift #available and @available directives to allow this.

No matter how I wrap the self.clipsToBounds = true statement, on these earlier versions of Xcode I get a Swift error telling me that clipsToBounds cannot be found.

Any help would be appreciated.

And solved (I think ...)

#if swift(>=5.9)
self.clipsToBounds = true
#endif

I think a better solution is:

        if #available(macOS 14, *) {
            self.clipsToBounds = true
        }

If you're compiling with Xcode 14 or earlier, that API isn't available in the SDK, so nothing is compiled and the value defaults to true on all macOS versions.

If you're compiling with Xcode 15 or later, the API is available, and this code sets the value to true, overriding the default of false on all macOS versions.

For details:

https://developer.apple.com/documentation/macos-release-notes/appkit-release-notes-for-macos-14#NSView

Note that the default value depends on what SDK you linked against, not what version of macOS is running.

Its not working for me.

I am using Xcode 14.3.1 . any suggestion ?

Swift has been released 10 years ago -

is there still no way to check for an SDK version at compile time..?
Hard to believe.

NSView.clipsToBounds not available
 
 
Q