__has_include check if a class exists against swift?

In objective-c, I have something like:

#if __has_include(<MyFramework/SomeFeature.h>) SomeFeature *h = [SomeFeature new] #else OtherFeature *h = [OtherFeature new] #endif 

How to check if a class exists in swift? This link has some answer. Loose connection - check if the class exists and if this class uses

The good thing about __has_include is that this is a compile-time check, but it only works for the objective-c header. Do we have something for quick? Or maybe what I'm doing is not a very good approach?

For example, I have a class Machine and it has a Gun method, if I turn on the Pistol framework, it will return Pistol . If I turned on both Pistol and AK47 , it would return AK47 because it has more rounds.

+5
source share
1 answer

Compile-time checking is still available in Swift, but they are much less reliable. To perform a compile-time check, you need to define a compilation condition and establish several new build configurations that can enable or disable conditions. Swift does not have a preprocessor (yet?), So this is the volume of your capabilities.

0
source

All Articles