简体   繁体   中英

#if canImport() not working properly with CocoaPods. Serious issue

we are experiencing really strange issue, which creates problems in our production code. Basically, we have created a framework, which has few separates optional frameworks. Right now, we access code from the framework with the following logic:

#if canImport(optionalFramework)
firstMethodFromTheFramework()
secondMethodFromTheFramework()
#endif

The problem is that, then we distribute our main framework with CocoaPods, even if client integrates additional Subspec, our code cannot reference additional frameworks.. so it does not import frameworks and does not call optional methods. So it does not work completely and creates tons of problems... We simply don't get it, why IOS development does not allow such features and such architecture?

It is much better to modulize frameworks, instead of creating gigantic frameworks, which would only increase size and complexity..

Maybe there are other ways of accessing framework from optional frameworks, if client integrates them?

We really feel kinda unsure about this whole situation and it is crucial for our whole project.

I will clarify one more time: our main framework does not include optional frameworks at all. It just uses #if canImport() flags. Client should be responsible for adding Pods and then framework should automatically start executing code

I have the same problem and it solved for me by the following :

install the optional pods in your framework -lets say it's Alamofire-(you will remove at the end) so you can find there path in both files

  1. yourFramwork.debug.xcconfig
  2. yourFramwork.release.xcconfig

from FRAMEWORK_SEARCH_PATHS copy this "${PODS_CONFIGURATION_BUILD_DIR}/Alamofire"

and from HEADER_SEARCH_PATHS copy this "${PODS_CONFIGURATION_BUILD_DIR}/Alamofire/Alamofire.framework/Headers"

put what you have copied anywhere lets say note file

now remove the pod (Alamofire) from the framework podFile and run pod install again

manually past what you copy in both files:

  1. yourFramwork.debug.xcconfig
  2. yourFramwork.release.xcconfig

as they where ,done right now if you add your framework to another project and install the optionalFramwork in the that project podFile every thing should goes fine

and #if canImport(optionalFramework). should work as you need

hope that solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM