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 iOS 8
. I would like to use the new Apple Speech
framework in the app, if it is available at runtime. I am aware of the #available(iOS 10, *)
directive for code sections, and the @available(iOS 10, *)
directive which can be used for an entire class. So I can easily avoid executing any code that uses the Speech framework with those. But in the file that contains the class that uses Speech, I need the "import Speech" statement, and neither of those two directives can be used there. I am finding that even if I have the @available(iOS 10, *)
directive on my entire class, when I run my app on an iOS 9 device it is killed at launch with
"dyld: Library not loaded: /System/Library/Frameworks/Speech.framework/Speech".
Am I missing something, or is it only possible to use the Speech framework in an app that has deployment target of 10?