Mostafiz Rahman
Mostafiz Rahman

Reputation: 8522

Xcode can't find Alamofire, error: No such module 'Alamofire'

I'm trying to include Alamofire in my Swift project following the github(https://github.com/Alamofire/Alamofire#cocoapods) instruction.

I've created a new project, navigated to the project directory and run this command sudo gem install cocoapods. Then I faced following error:

ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/pod

After searching I managed to install cocoapods by running this command sudo gem install -n /usr/local/bin cocoapods

Now I generate a pod file by pod init and edited it this way:

# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'


target 'ProjectName' do
  # Comment this line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!


  # Pods for Law
    pod 'Alamofire'
  target 'ProjectNameTests' do
    inherit! :search_paths
    # Pods for testing
  end


  target 'ProjectNameUITests' do
    inherit! :search_paths
    # Pods for testing
  end


end

Finally I run pod install to install Alamofire. After that I open the project and import Alamofire statement gives me following error No such module 'Alamofire'

Update-1: Results of pod install is:

Analyzing dependencies
Downloading dependencies
Using Alamofire (3.4.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

Upvotes: 12

Views: 21947

Answers (12)

M Murteza
M Murteza

Reputation: 1744

enter image description here 1: Select Pod

2: Select Almofire

3: Search Architecture in build Setting

4: Build Active Active Architecture Only set to No

5: Clean Build and Run.

This work for me.

Upvotes: 0

Kudos
Kudos

Reputation: 1490

After a lot of efforts and all solutions provided above. I have fixed on Xcode 13.0:

Use for Simulator: Go to:

- Build settings -> EXCLUDED_ARCHS = arm64
- Build settings -> VALID_ARCHS = arm64e armv7 armv7s arm64  x86_64

Use for Realm Device: Go to:

- Build settings -> EXCLUDED_ARCHS = 
- Build settings -> VALID_ARCHS = arm64e armv7 armv7s arm64 

Upvotes: 1

2021 M1 USERS

according to: https://developer.apple.com/forums/thread/123614?answerId=683594022#683594022

  • close XCode
  • open Finder app and show there "Applications"
  • right click on icon Xcode and click on "Get info" (or something similar)
  • there is checkbox "Open with Rosseta" (or something similar). Select it
  • run Xcode again and try to build

it worked for me hope it works for you.

Upvotes: 1

Abdul Momen
Abdul Momen

Reputation: 407

When using Cocoapods to include dependencies always open your .xcworkspace

  • In Podfile use use_frameworks!
  • Remove any linked libraries from build phases.
  • In Build Setting look for Framework Search Path and add $(inherited) in both debug and release.
  • Do the same for Header Search Path too.

Now try a clean build.

Upvotes: 0

Maysam R
Maysam R

Reputation: 969

go to Product -> Scheme -> Manage Schemes... and check Alamofire truesample image this work for me

Upvotes: 8

yin seng
yin seng

Reputation: 87

you have to clean project and build, before you can import that library.

Upvotes: 2

Boris Legovic
Boris Legovic

Reputation: 220

Sometimes with no reason xcode can't load a module Alamofire. It can happen after a work session, after opening a project. The fix for this is to select a schema -> Alamofire, and run. If the message is "Successful", the schema can be changed back to project and it will work with no problems.

Upvotes: 3

ciccioska
ciccioska

Reputation: 1291

I suggest you to change your pod file like this below:

# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
 use_frameworks!

pod 'Alamofire', '~> 3.0' <<<----  Alamofire library is cross beetween projects

target 'NotifyM' do

end

target 'NotifyMTests' do

end

target 'NotifyMUITests' do

end 

Another thing is use_frameworks! you should use this if the project is Objective-C based and try to use Swift pod library.

UPDATE: for the new cocoapods version 1.x the shared library should be like this:

# There are no targets called "Shows" in any Xcode projects
abstract_target 'Shows' do
  pod 'ShowsKit'
  pod 'Fabric'

  # Has its own copy of ShowsKit + ShowWebAuth
  target 'ShowsiOS' do
    pod 'ShowWebAuth'
  end

  # Has its own copy of ShowsKit + ShowTVAuth
  target 'ShowsTV' do
    pod 'ShowTVAuth'
  end
end

as indicated into cocoapods website :http://guides.cocoapods.org/using/the-podfile.html

Upvotes: 2

user4392177
user4392177

Reputation:

I suggest that and it's work for me :

platform :ios, '8.0'
use_frameworks!

target 'App' do
  pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git'
  pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'

end

After that, run : pod install in your project repository

Upvotes: 1

Anand Nimje
Anand Nimje

Reputation: 6251

Install this way Pod file

# Uncomment this line to define a global platform for your project
 platform :ios, '8.0'
# Uncomment this line if you're using Swift
 use_frameworks!

target 'NotifyM' do

pod 'Alamofire', '~> 3.0'

end

target 'NotifyMTests' do

end

target 'NotifyMUITests' do

end

Upvotes: 1

Diogo Antunes
Diogo Antunes

Reputation: 2291

Open the .xcworkspace not the .xcodeproj

Upvotes: 14

Archie
Archie

Reputation: 150

You should tap the Target to select Alamofire and build it once before coding.

Upvotes: 0

Related Questions