13

I am trying to use Alamofire within a custom framework that I am creating. I created my custom framework project, added the Podfile, installed Alamofire. I then created a sample project to test out my custom framework.

The sample project is compiling fine with my custom framework import, that is until I started making Alamofire calls within my framework. Now Xcode is complaining about "Missing require module 'Alamofire'" within my sample project. And if I add "import Alamofire" to the swift file, Xcode now complains about "No such module 'Alamofire'"

Is if possible to use a swift framework such as Alamofire within a custom framework, and does the project using my custom framework need to import the Alamofire framework as well?

user4781334
  • 374
  • 2
  • 8
  • Did you open the xcworkspace or the xcproj? – Schemetrical Apr 13 '15 at 05:47
  • I am using the xcworkspace created by Cocoapods, and added the sample test project to it. – user4781334 Apr 13 '15 at 06:11
  • Did you link the cocoapods library inside Link Binary With Libraries? – Schemetrical Apr 13 '15 at 06:14
  • Did anyone get any info on this? – Hector Matos Apr 21 '15 at 23:03
  • In the end I decided to just use Alamofire.swift as it is without importing it as a framework. – user4781334 Apr 28 '15 at 06:23
  • I am facing the same problem . I would like create one custom framework that has dependency on Alamofire. I included Alamofire with cocoa pods. but not able to import Alamofire in swift file. Please suggest if have any solution for the same – Sunita Mar 01 '16 at 05:42
  • @user4781334 you can add third party library while creating your custom framework as follows...clean your project several times or restart your xcode if possible. I am able to solve the same problem with clean of project – Sunita Mar 01 '16 at 06:51

2 Answers2

3

Yes, it is possible to use Alamofire within your custom framework, but you need to also include Alamofire in the podfile of your sample project (the project that uses your framework). Your podfile should look like this:

platform :ios, '8.0'
use_frameworks!

target 'MyApp' do
#   pod 'MyFramework'  Include MyFramework if it is a cocoadpod
   pod 'Alamofire'
end

The error "Missing required module 'Alamofire'" happens because your framework doesn't actually include Alamofire when you use it in some other project, and you cannot import Alamofire in your sample project for the same reason.

If you plan to make your project a Pod you can include the following line in your podspec:

s.dependency "Alamofire", "~> 3.1.5"

Including Alamofire as a dependency in the podspec instructs cocoapods to also include it when your framework is installed.

Hope it helps.

juanjo
  • 3,737
  • 3
  • 39
  • 44
1

Not 100% sure if this is your issue of not, but for swift stuff you have to use the use_frameworks! directive in your Podfile. Could that be the issue?

I ran into this once and found answer from https://www.raywenderlich.com/97014/use-cocoapods-with-swift

Fiid
  • 1,852
  • 11
  • 22