I am using XCode 8 + Swift 3.
I created a fresh iOS project named "MyApp".
Then, I create a Cocoa touch framework project, named "MySubProject". (The idea is to have MyApp project accessing MySubProject code.)
They are on the same level folder:
- MyApp/
- MySubProject/
I added MySubProject into MyApp project, linked the MySubProject framework. Everything works fine. My project structure looks like this:
All works until here! (MyApp code can access MyService code)
Now, I need MySubProject to use Alamofire to communicate with backend. So, under MySubProject/
I setup the Alamofire with CocoaPod, which creates the MySubProject.xcworkspace
.
I think I need to remove the previous MySubProject.xcodeproj
and using MySubProject.xcworkspace
, so I deleted the reference of MySubProject.xcodeproj
& add the MySubProject.xcworkspace
to MyApp
, it then looks like this:
As you can see, I can not see the source code of MySubProject now.
What is the correct way to use Alamofire or any 3rd party library through CocoaPod in Framework sub-project?
===== UPDATE ======
I need to add Alamofire into MySubProject
, not MyApp
. I followed instruction in Alamofire offical website to manually add Alamofire to MySubProject
, the project structure then looks like this:
- MyApp
- MySubProject.xcodeproj
-Alamofire.xcodeproj
After that, I can access Alamofire in MySubProject, no compile error. However, when I run my app in emulator, I got runtime error:
Referenced from: /Users/myname/Library/Developer/Xcode/DerivedData/MyApp-hezjlyvzxnavccenabxdepgftbrg/Build/Products/Debug-iphonesimulator/Alamofire.framework/Alamofire
Reason: image not found
How to solve that?
You can do this three different ways.
1) Add the dependency directly to you MyApp project
2) Build the MySubProject and add the library with the dependency in it to the MyApp project. (assuming the MySubProject will be a library)
3) When using custom pods you can provide a dependency in the .podspec file. Via this method I can import my own library (as a pods) which depends on other Cocoapods.
EDIT: After a good look we came to the conclusion that the methods above didn't met leem.fin's specific requirements. It's NOT possible to include a framework into another framework. But there're two other options:
1) Ship the secondary framework besides your framework and link it to your own framework. This way both MySubProject and MyApp can link to that framework.
2) Import the sources directly into MySubProject so they'll be compiled with the MySubProject.framework and they're accessible for other targets that simply link to MySubProject.
The easiest way is importing the sources directly into the MySubProject. If you don't copy the resources but link to the folder, you can git update the sources when you need to to get the latest changes.
来源:https://stackoverflow.com/questions/45281648/use-3rd-party-pod-in-sub-project-framework-project