Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR "swiftc failed with exit code 1" when converting to latest syntax

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.

like image 567
ctpanchal Avatar asked Jul 21 '16 06:07

ctpanchal


12 Answers

Have you tried to do clean with Clean build folder?

The combination keys is:

ALT + SHIFT + COMMAND + K

like image 177
David Avatar answered Oct 05 '22 12:10

David


Try delete Derived Data folder and Build it.

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

like image 45
Manuel Avatar answered Oct 05 '22 11:10

Manuel


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!!!

like image 32
MRizwan33 Avatar answered Oct 05 '22 12:10

MRizwan33


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
like image 45
Alaa Awad Avatar answered Oct 05 '22 12:10

Alaa Awad


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

like image 25
Sanket Ray Avatar answered Oct 05 '22 11:10

Sanket Ray


Just remove inactive file(deleted file) from Build phases

then

Clean Xcode. (cmd+shift+k)

like image 37
Rabie Avatar answered Oct 05 '22 12:10

Rabie


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

like image 34
Gowtham Sooryaraj Avatar answered Oct 05 '22 11:10

Gowtham Sooryaraj


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

like image 20
ivoroto Avatar answered Oct 05 '22 11:10

ivoroto


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.

like image 36
Vishnuvardhan Avatar answered Oct 05 '22 11:10

Vishnuvardhan


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

like image 43
garg Avatar answered Oct 05 '22 12:10

garg


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

like image 42
mohit Avatar answered Oct 05 '22 12:10

mohit


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.

like image 28
xdeleon Avatar answered Oct 05 '22 11:10

xdeleon