#if canImport(module) still does not solve conditional import statement in Swift 4.1?
you need to include the called functionality of your IceCream framework also with that macro like
#if canImport(IceCream)
let iceCream = IceCream()
let text = iceCream.toString()
#else
// and now?
#endif
And you should think about the else code.
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):
This, combined with your use of @available, should prevent the system from trying to load it on the devices where it is not available.
How can I conditionally depend on a system library for desktop vs iOS?
Your code totally works! Additionally, you can also use:
#if canImport(AppKit)
#endif
Or even:
#if canImport(CGLFW)
#endif
It depends on what you prefer!
Related Topics
Wkwebview Won't Load (Nsviewcontroller, Os X)
Swift Difference Between Double and Float64
Difference Between Sort and Sortinplace in Swift 2
Convert/Wrap Swift Struct as Nsvalue for Caanimation Purposes
Sbdata Is Wrong When Sbvalue Comes from a Swift Dictionary
Uitableview Only Displays One Section
Converting Scanlocation from Utf16 Units to Character Index in Nsscanner (Swift)
How to Create a Smooth Colour Change Animation Using Swiftui? (Example in Question)
How to Observe Object's Property in Rxswift
How to Override Internal Framework Method in Application (Outside Framework)
Xcodebuild Commands Failed to Generate Ipa
Destructuring Tuple of Tuple in Closure
Module Compiled with Swift X.1 Cannot Be Imported in Swift X.0.2
Why Is The Leading Swipe Action Also Duplicated as a Trailing Action
How to Access to a Static Cell