Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#if canImport(module) still does not solve conditional import statement in Swift 4.1?

Tags:

ios

swift

swift4

My App supports from version iOS 9. One of the frameworks that I am adding Icecream framework to sync realm objects needs iOS 10 or greater.

How to make the import of the framework conditional?

I have tried making the IceCream framework as optional under Linked frameworks and libraries under projects General tab

In Swift 4.1 you can have conditional import using canImport directive, like the one below which I have tried.

#if canImport(IceCream)
  import IceCream
#endif

The above import statement still throws a build error: Modules deployment target is iOS10

What configuration am I missing?

like image 256
Imran Avatar asked May 30 '18 16:05

Imran


1 Answers

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.

like image 179
Karsten Avatar answered Nov 01 '22 11:11

Karsten