Conditionally import a framework (such as Speech) based on iOS Version in Swift?

后端 未结 2 1866
你的背包
你的背包 2020-12-10 11:44

Is there any way to conditionally import a framework in Swift based on runtime iOS version?

In particular, I have an app with a deployment target of

相关标签:
2条回答
  • 2020-12-10 12:25

    You can make the Framework optional (details and image from Ray Wenderlicht):

    This, combined with your use of @available, should prevent the system from trying to load it on the devices where it is not available.

    0 讨论(0)
  • 2020-12-10 12:43

    You need to use

    #if canImport(YourFramework)
    import YourFramework
    #endif
    

    instead of @available now, after setting your framework as optional :-)

    0 讨论(0)
提交回复
热议问题