65

I am getting this error on archive:

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

How to solve it?

Please see the screenshot.

error

Cœur
  • 37,241
  • 25
  • 195
  • 267
R_Developer
  • 864
  • 1
  • 7
  • 10
  • 2
    Same here. Anyone have a resolution yet?!?!? – Mark McCorkle Oct 13 '14 at 17:01
  • I don't have solution for this. Somehow the code got executed. Somewhere in the code I have written some thing that was creating problem. Actually, I was handling the Dictionary it had some issues. But, I don't know why xcode was not at all showing any error on those line. Finally, I commented the code and code was executed. – R_Developer Oct 14 '14 at 09:20
  • Check this answer - http://stackoverflow.com/questions/25889723/swift-failed-with-exit-code-1-while-compiling-in-xcode-possibly-related-to-bri/27271734#27271734 – Kampai Dec 03 '14 at 12:30

24 Answers24

99

This problem occurs when the Swift optimization level is not set to None for Release. Set the value to None and the issue goes away.

  1. Open up your project and click on the projects root directory.
  2. Click the build settings tab.
  3. Search for Swift Compiler - Code Generation and under Optimization Level make sure Release is set to None.

EDIT

After upgrading to Xcode 6.1 these instructions caused other issues when archiving (building for debug/device worked fine). Setting the optimization to Fastest allowed me to archive again. There are apparent issues with Swift compiling still (archiving specifically).

Can't archive working 6.0.1 Swift project in Xcode 6.1 / Segmentation fault: 11

EDIT I was not able to fund the Build Settings tab, until I read this answer.

how to find the build settings tab

Community
  • 1
  • 1
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
34

This occurred for me when I had two of the exact same files, and also when I was missing I file I didn't know I had deleted. I clicked on the error message, and just above the error, it shows you what file you have more than 1 of or are missing.

Henry F
  • 4,960
  • 11
  • 55
  • 98
  • 2
    For me it was a file that had been deleted from the project but was still referenced on the other computer. Your suggestion about git commits helped a ton! – Erik Johnson Jan 05 '16 at 16:36
  • How did you add the file again? – DevC May 03 '16 at 10:31
  • 1
    This led me into the right direction. Thank you John! – ixany Nov 18 '16 at 09:33
  • 1
    For me the issue was that I had deleted a file from project without removing the reference. I had removed the file from terminal but the non existent file was still being referenced in the project. – dannysood Feb 21 '17 at 12:24
16

You can click the Product in the navigation and choose the "Clean" button; it will clean all compile error in your project. Then, you can debug for the latest error.

durron597
  • 31,968
  • 17
  • 99
  • 158
庄景鹏
  • 960
  • 9
  • 7
8

Deleted files reference keep in Build Phase and that's why it gives this error. Remove reference from there as well.

Project> Target > Build Phase

Under this section you will find your deleted files in red colour. Remove these files error will resolve.

FARAZ
  • 645
  • 7
  • 6
4

I am not sure if it has one solution. I recommend you to check the differences between your last git commit, and comment on/off the changes.

In my case, my code was

let anArray = ResultDict["ResultSet"] as [[NSDictionary : AnyObject]]
for aDict : NSDictionary in anArray {
    let anObject = ObjectType(ObjectDict: aDict)
    objectList.addObject(aDict)
}

no warning on the line, i got the same exit 1 compile error then i changed it to the below it has compiled.

let anArray = ResultDict["ResultSet"] as [[NSDictionary : AnyObject]]
    for aDict in anArray {
        let anObject = ObjectType(ObjectDict: aDict)
        objectList.addObject(aDict)
    }
Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
3

I don't know if this is really an answer, but...

I had the same issue. App worked when building/running, but archiving failed with "...swiftc failed with exit code 1", with no other helpful message at all. Luckily, when I tried to build my app with Nomad's ipa build, I got:

The following build commands failed:
    CompileSwift normal arm64 /path/to/erroneous/TableViewController.swift

So I started commenting out sections of that file and tracked the problem down to a tuple assignment.

// MARK: - Table Data

private var tableData: [(sectionName: String, item:ListItem)] = []

private func refreshTableData() {

    // let labor = ("Labor", laborListItem)                 // DOESN'T ARCHIVE
    let labor = (sectionName: "Labor", item: laborListItem) // ARCHIVES

    tableData = [labor]

    tableView.reloadData()
}

So apparently the compiler wanted the elements in thast tuple named (as defined by the type of tableData).. but only for archiving? The Dumb thing is, I use this same pattern in other view controllers, and the compiler seems to be fine with those.

For the record my Code Generation -> Optimization Level was set to None for debug and release.

Hope this helps someone! It took hours to figure this out.

RyanM
  • 4,474
  • 4
  • 37
  • 44
3

It happened to me when I didn't put the parenthesis at the end of a call of a function:

let var = self.getNextPrimeNumber

solved it by:

let var = self.getNextPrimeNumber()
danywarner
  • 928
  • 2
  • 15
  • 28
3

In my case, it was caused by duplicate files, using the same name, in my project directory. As soon as I removed them, the error was gone.

Dimitri T
  • 921
  • 1
  • 13
  • 27
1

This happened to me when I used static inline function from swift file

The function looks like this

static inline void openURLInSafari(NSString * _Nonnull urlString) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];}
M.Othman
  • 5,132
  • 3
  • 35
  • 39
1

this error comes from missing files so the compiler couldn't find the files and keep alerting. Follow these steps to rebuild your app:

  1. Look up for the red and invisible files within workspace
  2. Remove their reference
  3. Re-add files
  4. Re-compile
Cœur
  • 37,241
  • 25
  • 195
  • 267
Tran To
  • 285
  • 1
  • 6
1

I just had the same thing occur. I hunted down the cause to one file that caused the error even when empty. Examining the file, I discovered it had the wrong character set. When I set it to UTF-8, the error vanished. I think that it was decoding it with the wrong character set.

From this I surmise that the error simply indicates that something has happened that the compiler was unprepared for. Sorry that isn't very helpful to most people, but it may help to check your characters sets.

Owen Godfrey
  • 3,361
  • 2
  • 22
  • 18
1

This error occurred for me after I noticed that a few of my .swift files were inexplicably in the wrong directory -- one level above my Xcode project directory. When I noticed this, I moved them into the main project directory and cleaned the project, thinking everything would be fine. However, upon building the project I got the above-mentioned "failed with exit code 1" error. Just above the error message it listed the files I had just moved, indicating that it couldn't find them in the directory where they used to be. In addition to the error message, the files I moved were now showing up as red in the file navigation pane.

For each of the files in question what I did to resolve this was: - Select the file from the list of files in the Xcode file navigation pane, - Click on the little page icon in the rightmost pane of Xcode, which opens a file attributes pane, - Click on the little folder icon underneath where it says "Location" in the file attributes pane, - Choose the new location for the file, - RESTART Xcode for the above changes to really do anything.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ClayJ
  • 377
  • 2
  • 14
1

one more case that can lead to this error which just took me hours to track down: a failable initializer that always returns nil.

i had an initializer that looked like this:

init?(object: MyObject) {
    if object.importantProperty {
        // initialize
    }
    return nil
}

when what i meant was:

init?(object: MyObject) {
    if object.importantProperty {
        // initialize
    }
    else {
        return nil
    }
}

fixing the initializer made the error go away.

cforkish
  • 11
  • 1
1

If using Core Data:
I had a Core Data entity for which I created the NSManagedObject subclasses (with Xcode's help). In addition, the entity was configured to generate code automatically (see screenshot), so basically 2 classes existed during runtime. Just switch the option to Manual/None and it won't generate it.

enter image description here

Shaked Sayag
  • 5,712
  • 2
  • 31
  • 38
0

I experienced this error after performing a git merge. I solved new Xcode warnings and the project can be compiled.

Xcode 7.2.1 is used in my case.

oOEric
  • 1,069
  • 1
  • 10
  • 25
0

In my way the error was due to UIDevice.currentDevice() in ((UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0)

After commenting this all starts work fine.

XCode 7.2

vkalit
  • 647
  • 8
  • 19
0

in my case , at your project target Build Setttings, in Other Swift Flags,jsut delete the String "-serialize-debuggin-options" enter image description here

sunshine
  • 81
  • 1
  • 6
0

In my case, the error was the result of missing files that were generated by Xcode. I tried the regular clean Opt+Shift+K and it didn't clean up all the errors. I found a post on the Apple Developer site that recomended going to the Product Menu in Xcode, holding down the opt key, and selecting Clean Build Folder. This appears to be a more comprehensive build as it pops up a modal dialog for you to confirm.

Cœur
  • 37,241
  • 25
  • 195
  • 267
curt
  • 4,422
  • 3
  • 42
  • 61
0

I had a resolution very similar to RyanM, where with an excess of hubris I tried to assign a variable to the default value of an inner function:

Fails to compile (though does not crash SourceKit):

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    func itemCell(_ indexPath: IndexPath = indexPath) -> UITableViewCell {//...}

Succeeds:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    func itemCell(_ indexPath: IndexPath) -> UITableViewCell {//...}
Community
  • 1
  • 1
Stan
  • 434
  • 1
  • 4
  • 14
0

One possible reason that this can happen is perhaps because you have deleted a file but not removed references to it. This will mess up the pbxproj file. I would check to see if that is the case.

haxgad
  • 387
  • 4
  • 9
0

check "Development Pods" Folder all listed Frameworks path.

0

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

  1. keep 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 Happy Coding!!!
MRizwan33
  • 2,723
  • 6
  • 31
  • 42
0

So, I had the above and narrowed it down to a TFS issue with locking the file but only when I pasted or did any other edits besides small copies or manual typing. I noticed the original file would compile, but my edits wouldn't, even though they were syntactic OK. Also related is unable to save document: xcode The document "..." could not be saved

The fix for both was:

  1. Duplicate working version.
  2. Paste fully-merged new code into duplicate.
  3. Copy and paste old file over new one. (I personally just renamed the old one to something else, then pasted duplicate and renamed it, too. Guessing both work since I pasted directly earlier for reverts during tests to see).

Voila. Lazy way to bypass merge-locking issue. Apparently full file-pastes are just fine, while edits aren't. Shared since the other answers don't seem to be as lazy as this. ;) Note: I am suspecting a non-UTF-8 character made its way somewhere, but pastes worked in older versions so I don't know where, or if relevant.

Stephen J
  • 2,367
  • 2
  • 25
  • 31
-1

Just go to the "project setting" and click on the "build phaces" after that you will find targets in that u have to delete the test file like my project name "WER" so its showing like this WER&TEST so just delete that and clean ur project and run .........

Teju
  • 1