ctpanchal
ctpanchal

Reputation: 731

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.

Upvotes: 58

Views: 92227

Answers (26)

green_knight
green_knight

Reputation: 1385

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')

Upvotes: 0

Jonathan Kopp
Jonathan Kopp

Reputation: 1

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.

Upvotes: 0

Janine Kroser
Janine Kroser

Reputation: 444

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

Upvotes: 0

MRizwan33
MRizwan33

Reputation: 2741

  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.

Upvotes: 10

mfaani
mfaani

Reputation: 36427

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.

Upvotes: 0

Peter Walter
Peter Walter

Reputation: 1003

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.

Upvotes: 0

Vishnuvardhan
Vishnuvardhan

Reputation: 5107

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.

Upvotes: 2

Praveen Reddy
Praveen Reddy

Reputation: 81

  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.

Upvotes: 0

Gurunath Sripad
Gurunath Sripad

Reputation: 1398

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.

Upvotes: 0

Sanket Ray
Sanket Ray

Reputation: 1141

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

Upvotes: 7

Rabie
Rabie

Reputation: 533

Just remove inactive file(deleted file) from Build phases

then

Clean Xcode. (cmd+shift+k)

Upvotes: 5

Akhilesh Mourya
Akhilesh Mourya

Reputation: 666

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).

Upvotes: 0

Nupur Sharma
Nupur Sharma

Reputation: 1214

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

Upvotes: 0

ivoroto
ivoroto

Reputation: 1035

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

Upvotes: 4

Balaji
Balaji

Reputation: 146

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.

Upvotes: 0

xdeleon
xdeleon

Reputation: 779

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.

Upvotes: 1

MRizwan33
MRizwan33

Reputation: 2741

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

Upvotes: 1

Chris Garrett
Chris Garrett

Reputation: 4924

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.

Upvotes: 0

mohit
mohit

Reputation: 154

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

Upvotes: 1

Gowtham Sooryaraj
Gowtham Sooryaraj

Reputation: 3917

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

Upvotes: 4

Alaa Awad
Alaa Awad

Reputation: 4182

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

Upvotes: 8

Kevin Morris
Kevin Morris

Reputation: 115

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

Upvotes: 0

Lucas van Dongen
Lucas van Dongen

Reputation: 9878

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.

Upvotes: 0

garg
garg

Reputation: 2727

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

Upvotes: 1

David
David

Reputation: 1172

Have you tried to do clean with Clean build folder?

The combination keys is:

ALT + SHIFT + COMMAND + K

Upvotes: 57

Manuel
Manuel

Reputation: 1695

Try delete Derived Data folder and Build it.

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

Upvotes: 12

Related Questions