0

Does anyone know of a way to use code from an optional subspec in the core subspec of a pod?

Example:

  • optional subspec contains the protocol: SometimesAvailableProtocol
  • in the core I want to define a variable of that type if it exists, something like:
#if canImport(SometimesAvailableProtocol)
    var sometimesAvailableVar: SometimesAvailableProtocol
#endif

However, unfortunately canImport only works with modules and we have noticed that if you use something like canImport(MyPod.SometimesAvailableProtocol) it works or fails randomly.

Daniel
  • 20,420
  • 10
  • 92
  • 149

1 Answers1

0

For future reference, you can use:

optional_subspec.ios.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "$(inherited) -D MY_SUBSPEC" }
optional_subspec.tvos.pod_target_xcconfig = { "OTHER_SWIFT_FLAGS" => "$(inherited) -D MY_SUBSPEC" }

and then in the core just do #if MY_SUBSPEC

Daniel
  • 20,420
  • 10
  • 92
  • 149