How do I include calls to methods only present in one operating system version when compiling for multiple versions?
-
06-07-2019 - |
Question
I have an app that is being compiled with a minimum system requirement of Tiger (OS X 10.4), but I need to include some code to deal with Spaces if the app is executing on Leopard (OS X 10.5).
How do I do this?
(The call I need to make is to -[NSWindow setCollectionBehavior:]
).
Solution
- Set your Base SDK (for all configurations of the target you're building) to the version of the OS that includes the call.
- Set the Deployment Version to the earliest OS you want your code to launch on.
- For all calls that don't exist in earlier versions of the OS, you must test before you call, either by using respondsToSelector: (for methods) or testing against nil (for functions and statics). You can if you like do a check for the OS version, but it's more robust to check the specific call.
The Cross-Development Programming Guide describes the techniques in detail.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow