10.14
with the appropriate version):@available
guards can be used in Objective-C(++) code.(In C++ code, you can use these nsCocoaFeatures
methods instead.)API_AVAILABLE
macros.For example, the definition of the NSVisualEffectMaterial
enum looks like this:@available
runtime checks.Metal.framework
(added in 10.11) and MediaPlayer.framework
(added in 10.12.2).dlopen
your framework at runtime (like we do for MediaPlayer),or you can use -weak_framework
like we do for Metal:MAC_OS_X_VERSION_MAX_ALLOWED
macro.MAC_OS_X_VERSION_MAX_ALLOWED
checks so that, if an SDK is used thatalready contains these declarations, your declaration does not conflict with the declaration in the SDK.API_AVAILABLE
annotations so that the compiler can protect you from accidentallycalling the API on unsupported macOS versions.API_AVAILABLE
advice, but it should.NSVisualEffectMaterialSelection
is available starting withmacOS 10.10, but it’s only defined in SDKs starting with the 10.12 SDK.)@interface
declaration and wrap it in the appropriate ifdefs.NSObject
.NSClassFromString()
.objc_allocateClassPair
and class_addMethod
.Here’s an example of that.__attribute__((weak_import))
annotations?dlsym
.#ifdefs
because there are no system headers you could conflict with.@available
runtime check helpers,and the compiler cannot warn you if you call APIs outside of availability checks.