When a method can only be used on certain iOS versions, I usually check for its availability using respondsToSelector:
.
With a const CGFloat
declaration this is not possible.
The specific constant I'm trying to use is UIFontWeightBlack
which is defined as:
UIKIT_EXTERN const CGFloat UIFontWeightBlack NS_AVAILABLE_IOS(8_2);
What is the best way to check if the iOS version my code is running in supports this constant?
Also if I want to support building my framework with older versions of the iOS SDK, what is the best way to check at compile time, if the used SDK offers this symbol?
I would currently do the check with
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_2
Is there a way to check for the symbol directly, without having to rely on / explicitly specify the iOS SDK version?
This is covered in the SDK Compatibility Guide.
Check the availability of an external (extern) constant or a notification name by explicitly comparing its address—and not the symbol’s bare name—to NULL or nil.
So your code would be:
if (&UIFontWeightBlack != NULL) {
// It is safe to use the constant
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With