37

Using Xcode 7

I am trying to install Alamofire in a sample project. Have used the instructions from Ray Wenderlich's page

Only change from above link is the podfile -- which is from GitHub page here because the version has been updated. I have also used the Swift 2.0 branch.

Below is the snapshop of the error, my pod file and my terminal post installing the pod

PODFILE enter image description here

TERMINAL enter image description here

P.S: I want to use cocoapods to install Alamofire. I don't want to download it from github page

Cœur
  • 37,241
  • 25
  • 195
  • 267
Anuj Arora
  • 3,017
  • 3
  • 29
  • 43

19 Answers19

75

The Trick for me was to open the .xcworkspace file rather then the original project file itself.

danroose
  • 825
  • 7
  • 6
29

working this:

Scheme -> Manage Schemes...

checked Alamofire checkbox → Build Alamofire scheme

and, if you used Playground , you should change settings Playground:

View -> Utilities -> Show File Inspector 

Platform OSX → iOS
satoshin
  • 309
  • 3
  • 3
  • 3
    It build successfully when selecting alamofire, but not working when I change my project. And show build failed and no such module in Alamofire importing... – Chandni Feb 23 '18 at 07:53
  • I was trying to run existing project developed using swift 2.0, on Xcode 9.2, and this solution has worked for me. – Pramod More Apr 20 '18 at 07:38
  • None of the solutions posted here so far work for me. – BadmintonCat May 08 '18 at 02:27
10

import Alamofire after importing UIKit Then comment it out, build the project first. Uncomment it. (this worked for me, and others, when the other answers did not).

Dimitri T
  • 921
  • 1
  • 13
  • 27
  • 3
    The other answers didn't work for me, I had tried everything and spent days trying to solve this. Perhaps for other readers this might help them. I have seen on another Q page re this exact problem that it was the solution for others too. It's not a magic trick, its a fix to a programming bug. Why not allow another solution? It's not repeating an answer in a thread, its offering another solution which might be the answer someone needs, and was not yet posted here. See here that this was the answer for several others: https://github.com/Alamofire/Alamofire/issues/122 – Dimitri T Apr 30 '16 at 20:45
  • This worked for me just now after NOTHING else worked! Crazy – Pierce Feb 01 '17 at 19:30
  • This works ... until the next clean. Then the problem is back. – BadmintonCat May 08 '18 at 00:40
9

Try this one.

For Swift 2.0 there is no need to add Alamofire.xcodeproj into your xcode. Simply copy and paste source folder from https://github.com/Alamofire and you are done.

or if you want to install Alamofire from Cocoapods then try below code.

  source 'https://github.com/CocoaPods/Specs.git'
  platform :ios, '8.0'
  use_frameworks!

  pod 'Alamofire', '~> 2.0'
Suraj
  • 145
  • 2
  • tried the cocoapod bit of code..did not work...says cannot load underlying module for Alamofire – Anuj Arora Sep 10 '15 at 13:00
  • I think you must try the copy and paste of source folder from Alamofire git project into your xcodeprj. or try to update your cocoapods to latest version. – Suraj Sep 11 '15 at 04:34
  • Yes..i did that and it worked..also I just needed to build the project even though the error was showing and then it was fine. thanks – Anuj Arora Sep 11 '15 at 06:43
  • Hi, I am extending Alamofire dependency as the same, but still getting "No such module" - My Xcode version in 7.2.1, OSX El Capitan etc. Please update as soon as possible. – Mohsin Khubaib Ahmed Apr 23 '16 at 04:12
5

For reference to anyone who comes across this problem in the future:

Swift 2.x + CocoaPods 1.x

Symptoms: build works in Xcode for debug configuration but fails when xcodebuild is executed from console using pod lib lint or similar command. The result is error: no such module 'X'

Solution: In MyProject.podspec add your dependencies without specifying versions:

spec.dependency "Alamofire"

The Podfile should also contain the same dependencies. Then run:

$ pod install && open MyProject.xcworkspace

You should open .xcworkspace instead of .xcodeproj. The build will now work in both Xcode and console and pod lib lint passes validation.

I wrote this because I was trying to publish a new CocoaPods pod library and had a similar issue but found no answer and also because Google leads to this question.

albogdano
  • 2,710
  • 2
  • 33
  • 43
5

Here is what to do:

  • close your project,
  • install your pod library,
  • then install alamofire.

After you do all things, don't open the file with extension .xcodeproj but open the file with extension .xcworkspace

Oerd
  • 2,256
  • 1
  • 21
  • 35
5

There is only one way to solve this issue.

Quit Xcode.

Delete project's temp files located at /Users/username/Library/Developer/Xcode/DerivedData

Delete ProjectName.xcworkspace

Delete Podfile.lock file and Pods folder Run pod install.

Open the newly created ProjectName.xcworkspace file and build.

credits to Dimitris Bouzikas here

Jay Shenawy
  • 953
  • 1
  • 12
  • 22
3

My problem was solved using these steps :

Clean Project Goto Project > Build Setting > Framework Search Path and add

  • "$PODS_CONFIGURATION_BUILD_DIR/Alamofire" as non-recursive
  • $(inherited) as non-recursive
  • $(SRCROOT) as recursive
Zeeshan
  • 4,194
  • 28
  • 32
3

Have been facing the same problem, following trick resolved the issue

Go to Manage scheme -> Select pod library that is causing issue -> Build

Change back the scheme to project and then run the app, you are good to go

Note: If you don't see the pod library in the scheme, go to Manage scheme and select the pod library that you would like to build.

sahiljain
  • 2,215
  • 1
  • 29
  • 39
3

Adding Alamo Fire to all of my target's build phases fixed it for me.

Alamo Fire Link Binary With Libraries

Eric Mentele
  • 864
  • 9
  • 16
1

After doing @satoshin answer, I also had to check the Shared box on the right hand side of the Manage Schemes window.

ewizard
  • 2,801
  • 4
  • 52
  • 110
1

go to finder locate the project and navigate to the '.xcworkspace' file. thats where your pods are installed. if you go to your original project '.xcodeproj' you will only the pod debug files. hopes this helps. took me a while to figure out the problem too.

tony Macias
  • 226
  • 3
  • 9
1

For me, solution was to exclude arm64 devices from Pods and Project. Image is in attachment.

Problem solved

0

I am using swift 3, I fixed this problem by deleting Derived Data for this project. Cheers...!!!

Harish Pathak
  • 1,567
  • 1
  • 18
  • 32
0

If clean project/restart xcode/reinstall cocoapods etc, did not work. You can try running Product -> Build for -> Testing (cmd + shift + u). The build failed but the import worked right after.

DoruChidean
  • 7,941
  • 1
  • 29
  • 33
0

As for me worked to change the name of the project. Accidentally put

ProjectNameTests

instead of

ProjectName

No schemas needed if you've configured the names correctly everywhere:

  1. Check Podfile
  2. Check which project file you've launched. (The white icon should be created for "xcworkspace")
  3. Product -> Clean Build Folder
  4. Product -> Build (Now you can run in a simulator).
  5. Start from the scratch, because most of the errors always occur in a cause of humanity mistake, not developers.
  6. If you've put the wrong name for project in Podfile check "Linked Frameworks...". If so - delete this framework. The path is showed below at screenshot.enter image description here

Example of correct Podfile (Alamofire):

'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target 'ProjectName' do
  pod 'Alamofire', '~> 4.7'
end
  • ProjectName should not contain any extensions(file types).
J A S K I E R
  • 1,976
  • 3
  • 24
  • 42
0

[For future seekers] you could have missed the second step from the below :

Go to Project Setting

  1. Go to Build Phase tab, create a new run script phase and add an input file to your Alamofire framework. In my case I set $(SRCROOT)/Carthage/Build/IOS/Alamofire.framework
  2. Go to General tab, scroll down to linked framework and libraries add Alamofire.Framework folder. You probably won't find it from list so you need to press "Add Other" button and introduce it yourself.
Iman Nia
  • 2,255
  • 2
  • 15
  • 35
0

For absolute newbie just close xcode project and open by the new way. Choose in your folder file which contains extension like this: .xcodeproj and just enjoy you life.

Roman
  • 245
  • 2
  • 4
0

You can start by making sure you open the Xcode workspace file (with the extension .xcworkspace) instead of the project file (with the extension .xcodeproj). The workspace file contains dependencies installed by CocoaPods, and it is necessary to use it to work on your project.

Sport
  • 8,570
  • 6
  • 46
  • 65