21

I'm trying to get CocoaPods working in a Swift project but this is my first time.

My Podfile is

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

pod 'Alamofire', '~> 1.2'
pod 'SwiftyJSON', '~> 2.2.0'

I run pod install but building it gives me this error:

Error: unable to read module map contents from 'Target Support 
Files/Pods/Pods.modulemap': Error Domain=NSCocoaErrorDomain Code=260
 "The file “Pods.modulemap” couldn’t be opened because there is no such file." 
UserInfo=0x7fac488d5af0 {NSFilePath=/Users/jt/tmp-ios/my-template/Pods/Target 
Support Files/Pods/Pods.modulemap, NSUnderlyingError=0x7fac457f0e90 "The operation 
couldn’t be completed. No such file or directory"}

The weird is that this is that /Users/jt/tmp-ios/ is not even the directory I am in.

Tue Jun 09$ pwd
/Users/jt/repos/EmbersSwift
Tue Jun 09$ 

I did have something in that directory before by what it is referencing that is not clear. How would I fix this? I suspect it is something in Pods.debug.xconfig but was hoping somebody had dealt with this before.

halfer
  • 19,824
  • 17
  • 99
  • 186
timpone
  • 19,235
  • 36
  • 121
  • 211
  • I have exactly the same problem. Did you find a solution for this? I have the feeling this errors keeps coming up and disappearing from time to time. I'm using Alamofire and SwiftyJSON as well, but it searches the modulemap in the wrong folder.... - I'm wondering if it has to do that the project uses frameworks? – skofgar Jun 15 '15 at 01:02

6 Answers6

44

The solution that worked for me was:

First step:
(this step may no longer be needed in Xcode 9.x and newer)

  1. Open Xcode
  2. Click Window (Menu Bar)
  3. Click Projects
  4. Remove all projects (e.g. use backspace)
  5. Close Xcode

Second Step:

  1. Open a terminal app
  2. cd ~/Library/Developer/Xcode/DerivedData
  3. rm -rf Build/* see below if you have a customized build location
  4. rm -rf ModuleCache/*
  5. Close a terminal app

Third Step:

  1. Open Xcode
  2. Product > Clean
  3. Product > Run

Source: https://stackoverflow.com/a/30752152/756976

If you have defined a custom build location:

  1. Go with Finder or the Terminal to the location of the build files. The location for these files is defined in Xcode. To check where these files are:
    • Open Xcode
    • Go to Settings -> Locations -> Derived Data
  2. Go to that location and delete the Build folder

Edit: June 9, 2016

It is also possible that this resolves your problem:

By default the clean of Xcode, does not delete everything, by going to Product, pressing the ALT-key, the Clean-button will change to Clean Build Folder....

skofgar
  • 1,607
  • 2
  • 19
  • 26
  • Can you explain why? – allenlinli Apr 27 '16 at 13:55
  • @AllenLin I am not sure. I would like to say it is (or was) a compatibility bug between Xcode, Cocoapods, Modules. Since it never occurred again later and I am also not able to reproduce this problem I assume that they resolved this issue, or at least did some improvements. – skofgar Jun 09 '16 at 15:45
  • 7
    I'm using XCode 8.1. In its Window menu, I don't see `Projects` (First step - 3.). Where can I find it? – quanguyen Nov 26 '16 at 07:23
  • @quanguyen did you find it ? – SoliQuiD Jun 02 '17 at 01:51
  • 1
    Use`pod deintegrate` + `pod setup` to fix totally – Igor Kislyuk Sep 29 '17 at 10:56
  • pod reintegrate and pod setup had no effect for me. – ScottyBlades May 31 '18 at 01:32
  • @skofgar, when I click on window I see Minimize, Zoom, Developer Documentation, Welcome to Xcode, Devices and Simulators, Organizer, Show Touch Bar, Bring all to Front, Pods empty tab. I don't see projects. – ScottyBlades May 31 '18 at 01:33
  • Hello @ScottyBlades, it looks like newer versions of Xcode (maybe 9.x) do not contain that menu anymore... I assume omitting step 1 didn't help? – skofgar Jun 01 '18 at 17:13
  • @ScottyBlades you might need to create a new question or send me some details. I will take a look and see if I have any input that might help. – skofgar Jun 04 '18 at 11:25
9

In my case I had made a few changes to my PodFile, got a similar error and just re-ran 'install':

% pod install

And I was back in business.

BCalder
  • 91
  • 1
  • 2
1

I solved my problem by removing the pods from the pod file, pod install, add them again, then pod install again.

looks like a pod was incorrectly installed.

SoliQuiD
  • 2,093
  • 1
  • 25
  • 29
0

A similar problem happened to me with core data when reseting changes that involved core new version from the source control (Git). it threw:

/Path/To/Model/Model.xcdatamodel: Failed to read data model Error Domain=NSCocoaErrorDomain Code=260 "The file “contents” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Path/To/Model/Model.xcdatamodel/contents, NSUnderlyingError=0x7fb632e558d0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

I was unable to build the project because of that error I've tried the above solution but it didn't work.

What worked for me was:

  1. Open the RootModel.xcdatamodel (Left click on the model and Show in Finder).
  2. Manually erase the Model.xcdatamodel that triggets the issue.
  3. Clean project (cmd+shift+k) and Run.

Hope this helps someone.

Andgh
  • 21
  • 3
0

The simplest way though is going to Xcode's Preferences

Preferences->Locations->Derived Data

Just deleting Derived Data folder does the trick. Just Clean and Build the project again after, should not throw any errors.

inokey
  • 5,434
  • 4
  • 21
  • 33
0

What worked for me was to go to the project directory, where the pod file is. and:

rm -f Podfile.lock
rm -rf Pods/

That actually removed all the culprits and I was able to build and run the project again.

( I also did the previously mentioned steps, removed build folder and module caches, but that didn't help)

arvidurs
  • 2,853
  • 4
  • 25
  • 36