12

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.
Mostafiz Rahman
  • 8,169
  • 7
  • 57
  • 74

11 Answers11

14

Open the .xcworkspace not the .xcodeproj

Diogo Antunes
  • 2,241
  • 1
  • 22
  • 37
8

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

Maysam R
  • 915
  • 10
  • 12
3

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.

Boris Legovic
  • 200
  • 2
  • 11
2

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

ciccioska
  • 1,291
  • 16
  • 22
2

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

yin seng
  • 87
  • 1
  • 2
1

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
Mostafiz Rahman
  • 8,169
  • 7
  • 57
  • 74
Anand Nimje
  • 6,163
  • 4
  • 24
  • 43
1

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

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.

1

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 
Kudos
  • 1,224
  • 9
  • 21
0

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

Archie
  • 150
  • 6
  • I don't find any option to add `Alamofire` in `Target Dependancies` from `Build Phases`. Any suggestion please? – Mostafiz Rahman May 23 '16 at 07:48
  • 1
    and if you do not see Alamofire in Target, you can click Manage Schemes to check it. – Archie May 23 '16 at 07:54
  • I don't find `Alamofire` in the Product->Scheme->Manage Schemes list. If I try to Add it doesn't shows `Alamofire`. If I try to import by clicking on settings icon it shows the `Alamofire` folder in the pod directory of the project. Is anything wrong there? – Mostafiz Rahman May 23 '16 at 09:06
  • Tried opening both the xcodeproj and xcworkspace. Unfortunately neither works! :( – Mostafiz Rahman May 23 '16 at 09:42
0

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.

Abdul Momen
  • 379
  • 2
  • 13