Using the newest version of cocoa pods (0.36) I am able to embed cocoa pods written in swift (e.g. Alamofire) into my swift project. Now I introduced a custom framework of m
Thanks so much for sharing @Pasta and @Matt Quiros and it solved my problem. So Ok, I just want to share a bit more about my case and hopefully that will be helpful.
Development environment
Xcode Version 9.1 (9B55)
Deploy iOS version: 10.0
Problem:
So I am working on a project named 'MyProject' where I imported 'Charts' library using CocoaPod. The same time, there is also a private framework 'MyFramework' imported in 'MyProject'. Here the problem is that I want to use 'Charts' in 'Myframework' and Xcode keeps telling me that 'Chart' library is unidentified.
Solution:
I closed 'MyProject' and opened 'MyFrameWork' and 'File' -> 'New' -> 'File...'. Create two config files and put them on the same folder level of '*.xcodeproj' file. One config file is called 'Pods-MyFramework.debug.xcconfig' and the other is called 'Pods-MyFramework.release.xcconfig'. (The file name could be anything but I am not sure whether the location of files matters). The following is file structure on disk and in my Xcode.
Now, close 'MyFramework' project and open 'MyProject' project, in my Xcode the file structure is shown below. Expand the 'Pods' folder under 'MyProject' level. You will see some config files, copy their contents to the config files your just created in 'MyFramework' project, debug.config -> debug.config, release.config -> release.config.
Then in one 'MyViewController' in 'MyFramewwork', I added 'import Charts' and just wanted to give it try on simulator and it ... passed. Yeah!! Then I added some code in the same VC to create a bar chart and ran successfully on real device and the bar chart showed on screen. Then I tried last step that @Pasta mentioned that adding 'Copy Files' option to 'Build Phases'of 'MyProject', it also ran successfully on real device. I removed again and it still works.
I identified the problem. There was simply no pods.framework in the Frameworks/ folder of the embedded framework.
This is due to the fact that the Pods-frameworks.sh don't actually copy things in the right directory.
I managed to fix this problem by:
That's it!
For any newbies out there like me, this part in the question might confuse you:
Adding the Pods.debug.xcconfig and the Pods.release.xcconfig file to the Configurations for the target of my own swift framework, in other words changing the build settings to do all the changes, that cocoa pods do to the build settings of my iOS App target, solves the problem.
To do this:
In your custom embedded framework's Xcode project, click on File
> New
> File...
> iOS
> Other
> Configuration Settings File
.
Do the above twice. You may name the files Pods.release.xcconfig
and Pods.debug.xcconfig
, respectively.
In your Project navigator, expand the Pods
Xcode project > Target Support Files
> Pods
. You'll see that there are similarly named .xcconfig
files there. Simply copy their contents to the file of the same name inside your custom embedded Swift framework.
Click your Swift framework's Xcode project file, select the project target (the blue one, not the yellow toolbox one) > Info
> Configurations
.
Expand the Debug
and Release
configurations. You'll likely see two targets under your Xcode project--the main framework target, and the test target. In the "Based on Configuration File" column, set the configuration files on the main target to be the Pods.debug
and the Pods.release
files that you created previously.
And then do @Pasta's answer.
If you're using your custom embedded Swift framework with other projects, this setup will break simply because other projects have different .xcconfig
settings (the Pods' .framework
may also be named differently).
I resorted to just adding Alamofire as a git submodule within my framework. NOTE: Going the git submodule
way requires you to add your custom framework to your main project's Embedded Frameworks
, as well as the Alamofire.framework
from inside your custom framework.