Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Alamofire with an iOS 8.0 Embedded Framework

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?

like image 224
user4781334 Avatar asked Apr 13 '15 04:04

user4781334


People also ask

Is Alamofire a framework?

And that's it! The Alamofire. framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.

Can I use Alamofire in SwiftUI?

Adding Alamofire Into Our ProjectLaunch a new Xcode, SwiftUI based project and add the Alamofire dependency. You can use Cocoapods, Swift Package Manager or Carthage, whichever works the best for you. Once that's done, simply import Alamofire into your Swift class.

How do I add Alamofire project to Xcode?

Open the new Alamofire folder, and drag the Alamofire. xcodeproj into the Project Navigator of your application's Xcode project. It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.


1 Answers

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.

like image 133
juanjo Avatar answered Sep 27 '22 00:09

juanjo