How to check NS_AVAILABLE_IOS using const CGFloat

When a method can only be used for some versions of iOS, I usually check its availability with respondsToSelector:.

With an announcement, const CGFloatthis is not possible.

The specific constant I'm trying to use is this 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 of my code supports this constant?


Also, if I want to support the creation of my framework with older versions of the iOS SDK, what is the best way to check at compile time if the SDK used offers this symbol?

I am currently checking with

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_2

Is there a way to test for a character directly without relying on / explicitly specifying the iOS SDK version?

+4
2

SDK.

() , , , NULL nil.

, :

if (&UIFontWeightBlack != NULL) {
    // It is safe to use the constant
}
+9

, :

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80200 // 80200 is the value of __IPHONE_8_2

, , SDK iOS.

, SDK:

. 1050 __MAC_10_5 #if : , , .

+1

Source: https://habr.com/ru/post/1615132/


All Articles