如何将 Objective-C 中的模块导入调整为某个最小的 OS 版本?

How to condition module import in Objective-C to some minimal OS version?

我正在 Objective-C 中开发一个针对所有 Apple OS 的库(macos、ios、watchos、tvos)。我使用的一些 Apple API 仅在 OS 的某个版本开始可用。 我用以下代码保护我的接口定义和 OS 版本相关代码:

API_AVAILABLE(macos(10.11), ios(9.0), watchos(2.0), tvos(9.0))

但是,我的模块导入似乎也导致基于 Cocoapods 的库构建失败。 例如,如果 OSLog 模块仅在 OSs 中可用,从根据上述 API_AVAILABLE(...) 规范的版本开始,我确实需要保护 @import OSLog; 带有类似于上面的 API_AVAILABLE(...) 的 #if 预编译器条件。

假设我的假设是正确的,我应该怎么做?

我认为以下应该可行:

#if __has_include(<os/log.h>)
  #include <os/log.h>
#endif