Reputation: 423
Based on the ios version, I want to import a particular class into my class. I have to do this purely through code only (Xcode and any other manual setting will not work in my situation). Any pointers on how this can be done?
For example
#import classA
//code to ensure if ios version > 3.0 then import classB
public class myClass{
...
}
Upvotes: 0
Views: 351
Reputation: 6517
It cannot be done. What is imported has to be determined at compile time, because importing is a compile-time action. The iOS version is unknown until runtime. At compile time you only know the deployment target and the SDK version.
I'd recommend using the usual Swift availability-checks (Apple docs) and weak linking where necessary. Or you could raise the deployment target, if that's an option. Or you find a library that solves the problem even for the lower iOS version.
Upvotes: 1