0

I am developing an iOS App and a CocoaTouchFramework. The iOS App depends on the framework. My goal is to use a 3rd party Framework (in this case AlamoFire) inside my CocoaTouchFramework. According to this Stack Overflow link it is discouraged to have a Framework embed another framework. The way I understand it is that the consuming iOS App (the app which depends on the framework) needs to provide the 3rd party dependency and that my framework can reference that dependency. I don't know how to set this up in Xcode however. Here is what I have currently set up in Xcode:

enter image description here

AlamoFireApp is the actual App and AlamoFramework is my own Framework that will use AlamoFire to perform various network requests. I embedded the AlamoFire dependency into the App. How can I use AlamoFire in the Framework now? I've tried linking to AlamoFire from within the Framework (Adding Alamofire.framework) in the Link Binary With Libraries section) but I always get the No such module 'AlamoFire' error when I try to import AlamoFire in my Framework's classes.

Any help is appreciated.

Community
  • 1
  • 1
cbbcloud
  • 479
  • 5
  • 15

2 Answers2

0

@cbbcloud you can make your own cocoa pods using alamo fire. All you have to do is add them as dependency in pod spec. And then you can import the use the framework to build your framework.

Pod::Spec.new do |s|
 s.name         = 'YourFrameworkName'
 //other info
 s.dependency 'Alamofire'

end

If you are new to cocoapods , follow this link https://guides.cocoapods.org/making/index.html

neprocker
  • 170
  • 5
  • Thank you for your answer. I would prefer not to use CocoaPods since I am using Carthage in my project. Is there any way to do this manually? I have an Xcode workspace with 2 projects. One is the app project and the other my framework. I want to be able to use AlamoFire in the Framework. I've read that I should not include AlamoFire directly in my framework but that my main app project should provide the AlamoFire dependency. My question is just how can I call the AlamoFire code in my framework without including AlamoFire directly in my framework? – cbbcloud Oct 08 '16 at 23:06
0

Ok I've found a way to do it. I was able to solve the problem by dragging the AlamoFire.Framework into my framework (in this case, AlamoFramework) in Xcode. The important part that makes this work is to check the 'Copy items if needed' checkbox.

enter image description here

After checking this, the compiler can resolve the Alamofire module and there are also no linker issues. However this approach seems to contradict the recommendation of Rob Napier in his answer to this question that states:

The only appropriate time to link dependencies is at the application layer.

I haven't done full-time iOS development for very long so if anyone has any input they can give to clear up this issue, that would be great. But my problem has been fixed for now so I can continue with development.

Community
  • 1
  • 1
cbbcloud
  • 479
  • 5
  • 15