Say I have a Podspec that defines a MediaImporter framework. It has some classes in a Core subspec (which is marked as the default subspec) and also includes 2 optional subspecs:
- MediaVideo
- MediaPhoto
These subspecs contain various classes specific to importing that kind of media. Let’s say one class in MediaVideo is called MediaVideoHandler. How do I check whether or not I can instantiate that class in my code, based on its inclusion in the project? Subspec files are just added to the module created by the Podspec (MediaImporter), so I can’t use #if canImport(MediaVideoHandler) because that’s a class and not a module and always returns false.
Note: I tried the solution in this answer: How to use code from optional subspec in core subspec
I put this in the MediaVideo subspec:
ss.ios.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "$(inherited) -D MEDIA_IMPORTER_MEDIA_VIDEO"}
However, only the #else block is ever run. I can see the flag in the Pod project’s target for MediaImporter.
And then in my code:
#if MEDIA_IMPORTER_MEDIA_VIDEO
// Instantiate `MediaVideo` class
#else
// Do something else.
#endif




