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

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


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

Making a framework optional

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


You need to use

#if canImport(YourFramework)import YourFramework#endif

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