58

I was trying to convert syntax of old Swift project to new one as per few suggestion on Stack Overflow I tried converting it through Edit > Convert > To latest Syntax that did not work properly instead I started getting new errors shown as below

Command/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

And

Command /usr/bin/ditto failed with exit code 1

enter image description here

I tried Xcode 6.0.1 Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1, but it's a different situation.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ctpanchal
  • 731
  • 1
  • 5
  • 9
  • 6
    All Googlers: This error is a "catch all" that can have many reasons. Cleaning often helps. If not, retrace your steps and find out which changes cause the compiler to fail. Then, [open a bug report](https://bugs.swift.org/). – Raphael Aug 15 '17 at 16:04
  • The other options is to build your code on the command line using 'xcodebuild', it some presents the errors in a more obvious way than the 'parsed' log output in Xcode. You'll then have better luck in finding the issue – maninvan Sep 08 '18 at 17:48

26 Answers26

55

Have you tried to do clean with Clean build folder?

The combination keys is:

ALT + SHIFT + COMMAND + K

Amit Singh
  • 2,698
  • 21
  • 49
David
  • 1,152
  • 16
  • 24
11

Try delete Derived Data folder and Build it.

Go to Xcode -> Preferences -> Locations for get the derived data path

Manuel
  • 1,675
  • 12
  • 18
9
  1. Clean Xcode. (cmd+shift+k)
  2. Quit Xcode completely.
  3. Open project again.
  4. Wait for Xcode to indexing files.
  5. Now run your project.
MRizwan33
  • 2,723
  • 6
  • 31
  • 42
8

Just had the same issue. For me it was because I had renamed some of the project directories. I had a ton of red files in my project navigator. To solve, follow these steps:

  1. click on the directory in project navigator where many files show as red
  2. Under "Identity and Type" in the File Inspector (on the right side), click Containing directory
  3. Select the new directories
  4. Rebuild - command shift K, command B
Alaa Awad
  • 3,612
  • 6
  • 25
  • 35
  • This was my case, I pull an empty git repo to copy my code to. After moving my project file to the new folder, I got this switch error. This answer fixed my problem, thanks! – chrilith Mar 13 '18 at 18:34
  • Yep. after merging a re-write some bloke did. gotta click around and find the red (missing/moved) files and then delete the red. Derived data, clean, et al did not work. – codeslapper Aug 13 '18 at 19:30
7

As far as I know there can be multiple reasons why a compiler fails. Although cmd+alt+shift+k will help most of the time. If this fails, then click on the error message and try to debug it.

For example in the image below, if you read the message, we get to know that, there has been a name duplication. Fixing the name duplication will fix the issue.

enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sanket Ray
  • 1,071
  • 1
  • 15
  • 24
5

Just remove inactive file(deleted file) from Build phases

then

Clean Xcode. (cmd+shift+k)

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rabie
  • 513
  • 5
  • 10
  • How did you remove the inactive file from build phases? – ScottyBlades Dec 06 '19 at 04:55
  • 1
    for me, this is what worked! I just went to see the Build phase and I realized that the file with the problem, was highlighted in a different color, and it had no path – noloman Sep 28 '21 at 14:54
4

delete Derived Data folder and Build it.

Go to Xcode -> Preferences -> Locations for get the derived data path or cmd+Alt+shift+k

OR

Just remove inactive file(deleted file) from Build phases

Gowtham Sooryaraj
  • 3,639
  • 3
  • 13
  • 22
4

Cleaning the project wasn't working for me, this is because I didn't pay attention to the message right above (Xcode highlights only the final command).

In my case it was

<unknown>:0: error: filename "FileDuplicated.swift" used twice: '/../filepath/FileDuplicated.swift' and '/../filepath/FileDuplicated.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
Command /../bin/swiftc failed with exit code 1

I had to change the name of one of the two files and it was solved.

Hope this can help someone, cheers

ivoroto
  • 925
  • 12
  • 12
2

In my case it was due to the few swift files which has been showed grayed out in the Build Phases section. After removing those files it was successful.

Vishnuvardhan
  • 5,081
  • 1
  • 17
  • 33
1

In my case I deleted few files from project and when try to commit the code, the files was showing there . To solve this issue. 1. Open terminal 2. Type git clean -n // it will show you list of files which are deleted from project but still are saved somewhere 3. Type git clean -f // All unwanted files will be removed

garg
  • 2,651
  • 1
  • 24
  • 21
1

In my case swift development snapshot was selected instead of xcode 9.2. here are the steps and image.

  1. xcode on screen and click on xcode top menu bar.
  2. Than go to toolchains option and check on xcode 9.2. thats it. enter image description here

Note: If no toolchain found in your xcode than download from Here and install it. (after installation restart xcode). Happy Coding!!!

MRizwan33
  • 2,723
  • 6
  • 31
  • 42
  • you should download the toolchain first and install it and restart your xcode toolchain can be found https://swift.org/download/#releases. if still have any problem u can ask. – MRizwan33 Jan 30 '18 at 06:57
  • Error isn't fixed after installing that toolchain package. – iSrinivasan27 Jan 30 '18 at 07:11
  • what kind of error its showing and have you installed .pkg toolchain file? and also restarted your xcode?. kindly provide you error details. – MRizwan33 Jan 30 '18 at 07:31
  • Yes i did install and got toolchain in Xcode. Same error retained – iSrinivasan27 Jan 30 '18 at 07:35
  • is toolchain visible in xcode? and is selected xcode version.. in toolchain? and have u applied again all methods above mention? – MRizwan33 Jan 30 '18 at 07:38
  • Thank you for the update. I solve the issue with the answer provided by David. But, really thankful for showing how to add the Toolchain option in Xcode. – Jiraheta Apr 26 '18 at 21:06
1

In my case, it was "Other swift flags". I had declared a flag there but not -D, so this was not getting recognized and resulted in the same error

mohit
  • 154
  • 2
  • 9
1

Ok, my turn now. In my case I had an existing project. I copied in a few files from another project. One of the files I brought in was SettingsViewController.swift and there was already a file by the same name I was not aware of. The files were in different directories of the project so no duplicate message was shown. The compile/link messages offered no clue to this. I figured out the issue by adding one file at a time to the project (there were 12 total) and the building each time until I found the offending file. I renamed the new file and project builds now.

xdeleon
  • 769
  • 8
  • 20
0

In my case it was a compiler flag change that didn't work well. It took a few compiles before it actually started failing though! Xcode caches what it compiles.

Lucas van Dongen
  • 9,328
  • 7
  • 39
  • 60
0

I just had this issue. It's due to path references. Have you been moving files around and/or copying folders? Check if .xcodeproj is inside or outside of the main project folder. Also, make sure that the project's file and directory structure are intact.

/yourFolderProjectName/ <-- contains your .xcodeproj file AND folder with Xcode project name

/yourProjectFolder <-- here are .swift, info.plist, assets folder, etc.

/yourProjectXcodeFile.xcodeproj

Kevin Morris
  • 115
  • 1
  • 1
  • 9
0

Another thing to check:

In my case I had deleted a row in the "Other Swift Flags" section in the Build Settings screen under the Release setting.

That row had been a value for a compiler flag key/value pair. So the key was there but not the value.

Once I deleted the key as well, then the build worked again.

Chris Garrett
  • 4,824
  • 1
  • 34
  • 49
0

I faced this issue while using the Swift auto-generated header file in my project (named as 'TargetName'-swift.h) to use Swift classes in Objective-C.

There was a typo in the file where I had imported this swift header. Correcting the typo helped me resolve the issue.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gurunath Sripad
  • 1,308
  • 2
  • 14
  • 24
0

This issue is happening because of pods

So Follow the below steps to resolve this issue

  • Remove all the pods and re-install again. Remove all the pods using below this command (rm -rf "pwd/Pods/")
  • Quit the Xcode and open it again and build the app with device (generic iOS device).
  • Now check this issue will be resolved.
Balaji
  • 146
  • 1
  • 2
  • 12
0
  1. Clean the build in Xcode cmd+shift+k.
  2. Update the pods.
  3. look the where errors showing.
  4. Add the missing files in Xcode.
  5. After Run the Code. Working fine.
Cœur
  • 37,241
  • 25
  • 195
  • 267
0

I had this error when Xcode found two .swift files with same name. Rename one of them and build again.

Nupur Sharma
  • 1,106
  • 13
  • 15
0

Wait for completing the indexing and run the project again. You must get an error then check it which may be Objective-c bridging file not found error. This error comes if you are using any Objective-C library or code directly in the project and your project unable to find the bridging file in the system. This issue basically caused by, if project is unable to find any file in the system which is using in the project (path issue).

Akhilesh Mourya
  • 666
  • 1
  • 4
  • 15
0

Try below if none of the above working for you.

My project location was desktop/my_project_folder

I tried all above then i made simple change.

I create one more folder on desktop past my project .

then... enter image description here

Cause of problem in my case:

This problem occurred when i change my project name in xcode & project folder name from desktop.

Peter Walter
  • 993
  • 6
  • 11
0

I was working on a private pod and was also pointing to it locally. I had made some file name changes.

Hence I was getting this error.

All I had to do was to run pod install so it would reflect the file name changes. After that it compiled.

mfaani
  • 33,269
  • 19
  • 164
  • 293
0

In my case I copied a core data entity and only renamed the entity but not the class. So go to your xcdatamodel and select the enitity > rename also the class name

Janine Kroser
  • 444
  • 2
  • 6
  • 23
0

Had the same issue but with duplicate file references. Deleting Derived Data and cleaning had no success. But I got it fixed by doing this:

Navigate to your project.pbxproj -> open with your text editor of choice(I use atom).

Command+F and find the duplicate file sources and then delete them.

Build/Run and should be fixed.

0

For me, it was the keychainAccess problem as described in this answer (my error messages were completely opaque, all I had to go by was 'failed with exit code 1')

green_knight
  • 1,319
  • 14
  • 26