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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With