Is it possible to have a custom availability macro like the __OSX_AVAILABLE_STARTING for instance. I need it to perform in the same way, I just need to change its name and the versions and number of parameters?
Is it possible to have a custom availability macro like the __OSX_AVAILABLE_STARTING for instance.
Share
Yes, certainly. Objective-C is a strict superset of C, so C macros are very much at your disposal, and that facility is simply a set of C macros that eventually expand to
gcc’s
__attribute__keyword to declare special attributes of a function.The relevant declarations are all in
Availability.hAvailabilityInternal.hTo refresh, you use the
__OSX_AVAILABLE_STARTINGmacro to tag a function declaration as being supported for a particular version, like this:So what do we need to implement this ourselves? If you strip their
support for two different OS (mac, iphone), the availability facility boils down to:
A macro that takes a version argument like
__MY_AVAILABLE_STARTING(<version>):Set of version arguments, like those in
Availability.h, that are valid arguments for the above:Another set of macros, like thos in
AvailabilityInternal.hthat specifies what should happen for each version (regular support, deprecated, unavailable, weak, etc). Again, this is a function of the compiler, seegcc docs(there are lots of other interesting options):And finally, where the buck ends, the macros that expand to the
__attribute__facility.For the ones I have above, you can just keep using Apple’s macros:
Or, of course, you can define your own craziness.
C Macros are powerful stuff, often overlooked. Good luck!