Conditionally import framework (e.g. speech) based on iOS version in Swift?

Is there a way to conditionally import a framework into Swift based on the iOS version to run?

In particular, I have an application with the goal of deploying iOS 8 . I would like to use the new Apple Speech infrastructure in the application if it is available at runtime. I know the #available(iOS 10, *) directive #available(iOS 10, *) for code sections and the @available(iOS 10, *) directive @available(iOS 10, *) , which can be used for the entire class. Therefore, I can easily avoid executing any code using the Speech framework. But in the file that contains the class that Speech uses, I need the expression "import Speech", and neither of these two directives can be used there. I find that even if I have the @available(iOS 10, *) directive @available(iOS 10, *) for my entire class, when I run my application on an iOS 9 device, it kills when I start using

 "dyld: Library not loaded: /System/Library/Frameworks/Speech.framework/Speech". 

Am I missing something, or can I use the Speech framework in an application for deployment 10?

+6
source share
1 answer

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

Frame creation optional

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

+4
source

All Articles