GM release of Xcode 6 compile
Asked Answered
M

21

28

I just downloaded the GM release of Xcode 6 and it won't compile with this error:

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

Any ideas on how to fix this?

Mudlark answered 10/9, 2014 at 23:1 Comment(2)
stackoverflow.com/questions/10373016/… please see this one. solved my problem:)Drought
All common answer did not solved my problem, I figure out that issue was pretty different -stackoverflow.com/questions/25889723/…Francklyn
G
70

This error can happen for numerous reasons, so this is meant to be a debugging hint. You may want to try using xcodebuild in the command line. It will give you details as to what files are the culprits.

To do this, open Terminal and go to your project folder. Once there, type in

xcodebuild -project YourProject.xcodeproj -scheme YourScheme

or if you're working in a workspace

xcodebuild -workspace YourProject.xcworkspace -scheme YourScheme

You may see A LOT of messages pop up, but at the very end of the output you should see the specific files that are causing the crash. Back in XCode, go into those files and start playing with some of the Swift syntax to see what's going on. In my case, it had to do with the setAttributeString function, but I've seen other people have issues with ! and ?.

Hopefully that will get you headed in the right direction.

Gastronome answered 10/11, 2014 at 16:11 Comment(6)
This helped me to find the real problemFriendship
Just an addendum: In my case, this error was popping because I was sending nil for an optional String parameter. Using "" instead got rid of the error.According
Also found this to be super helpful. Should be the accepted answer!Breaking
TryProjects/ContentOrganizer.swift:15:8: error: no such module 'Alamofire' import Alamofire ^ this is what i get. it does work in the simulator and my phone, but when i run or do a command line compile this is my problem. i tried removing alamofire and then it gets bothered by the next pod i imported. any ideas how to solve this?Embay
@Esq I think this is because cocoapods does stuff alongside the xcodeproj file to successfully compile, which would be why it's not finding the Alamofire module. This worked for me: xcodebuild -workspace MyProject.xcworkspace -scheme MyScheme You need to tell it to compile your workspace instead of just the projectBrezin
thank you so much, I was thinking I'll spend ages looking for the error reason in our huge project!Unset
P
10

I had to change my "Optimization Level" to None[-0none]

Target > Build Settings > Swift Compiler > Optimization Level.

Prospective answered 21/10, 2014 at 6:32 Comment(1)
I would warn that there are two settings named "Optimization Level", make sure you're changing the one under Swift Compiler section. I lost a few hours solving my case.Strother
N
7

My case was a little bit different and it involves enums and optionals. For the simplicity lets define

enum Animal {
    case Dog
    case Cat
}

func exampleAction(animal: Animal) {}

exampleAction(.Cat)

It will run OK. However as soon as I made the argument optional the error started to appear. So this code won't work:

func exampleAction(animal: Animal?) {}

exampleAction(.Cat)

To make it work I had to add explicit enum name in the method call. So the following code worked again:

exampleAction(Animal.Cat)
Normie answered 11/10, 2014 at 18:13 Comment(1)
Just to add my two cents, for me it was on a normal class (and not enum) like: myButton.setTitleColor(.grayColor(), forState: .Normal) has to be changed to myButton.setTitleColor(UIColor.grayColor(), forState: .Normal) with the UIColor class.Gavette
S
3

I think it occured for many reasons, what I have encountered is this situation,hope it could help you.

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) ){ [weak self] in

        // ...
        dispatch_async(dispatch_get_main_queue()) { [weak self] in

            // ...
            return

        }
    }

In the upper code,just delete "[weak self]" called capture list will remove the compiler error. It works for me.

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) ){ [weak self] in

        // ...
        dispatch_async(dispatch_get_main_queue()) {

            // ...
            return

        }
    }

xCode version is 6.1.1

Sulfuric answered 5/12, 2014 at 2:11 Comment(0)
G
2

May be the same issue Swift compile error in XCode 6 GM

I had the same problem, then I use git checkout old versions to find which commit cause the problem, and try to find the key problem code. My key problem code is something like this

func afunc() {
    class AClass() {
    }
    let ac = AClass()
    //....
}

Other code could make the same problem, occur in Swift Optimization, and swift compiler doesn't tell you the exact location. This must be a bug by Apple.

Grampositive answered 30/10, 2014 at 17:23 Comment(3)
Actually going back and finding the difference made it. In my case it was a struct local to a func which made it crash. The compiler is nice but still it's a late beta :-(Delmardelmer
@ThomasKilian I had the same problem. Here is my code: func base() -> Void { struct ColorStruct { var WHITE = "" init() { if let PP = delegate.PP { WHITE = PP.UI.Colors.WHITE } } } var COLOR = ColorStruct() }Gloam
@AndrewAnthonyGerst Swift/XCode really sucks. Astonishing how patient Apple users are. I'm sitting here cursing on an hourly basis...Delmardelmer
T
2

In my case i changed 3 places:

Target > Build Settings > Swift Compiler >

  • Optimization Level.
    • Debug: None [-Onone]
    • Distribution: Fastest [-O]
    • Release: Fastest [-O]

When i changed just Debug, i have errors like "Source Kit crashed...." This combination of parameters, works very good for me!

Tyratyrannical answered 2/11, 2014 at 11:39 Comment(0)
S
2

If you are using some API which should be used in early iOS version, you may get build failure. For example: If you are using UI_USER_INTERFACE_IDIOM() instead of UIDevice.currentDevice().userInterfaceIdiom to identify the device type, you will get this build error with no hint.

Submiss answered 23/4, 2015 at 10:59 Comment(1)
You xcodebuild in command line, you may get an error like this. "Global variable initializer type does not match global variable type! %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_" LLVM ERROR: Broken module found, compilation aborted!"Submiss
G
2

A lot of people have this issue (me included) due to the optimisation on the compiler. I don't consider turning off the optimisation a correct resolution - I want my code optimised to run as quick as it can.

re-running xcodebuild manually didn't do any good as it ran it without the optimisations as well.

However - the error screen gave me the swiftc command that was failing:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -target arm64-apple-ios8.0 -incremental -module-name SpaceCats -O -sdk /Applic...

The -O there is the optimise flag.

I re-ran this whole command in the projects directory (as per xcodebuild recommendation above) and amongst all the details I found the error below:

{
"kind": "finished",
"name": "compile",
"pid": 10682,
"output": "Bitcast requires both operands to be pointer or neither\n  %228 = bitcast i8* %227 to %VSs20UnsafeMutablePointer, !dbg !1322\nBitcast requires both operands to be pointer or neither\n  %324 = bitcast i8* %323 to %VSs20UnsafeMutablePointer, !dbg !1322\nBitcast requires both operands to be pointer or neither\n  %411 = bitcast i8* %410 to %VSs20UnsafeMutablePointer, !dbg !1322\nBitcast requires both operands to be pointer or neither\n  %498 = bitcast i8* %497 to %VSs20UnsafeMutablePointer, !dbg !1322\nLLVM ERROR: Broken function found, compilation aborted!\n",
"exit-status": 1
}

If you want it to go to a file instead of the screen, add " 2>filename" to the end.

I then had to find the pid (10682) in the file to see what it was compiling. I ran the command for that pid manually and it gave me the error for the specific file. Then it comes down to fixing the code.

Gurgle answered 1/5, 2015 at 4:32 Comment(2)
Good answer, we had this problem trying to do a release build. Non release builds worked just fine (not optimized) then switching to release, swiftc failed as per the error. Wish you could see all that output in XCode too...Pe
I had been stuck for days with that swiftc compiler error, and this my friend, this brings me to life again. If one day you need a place to stay, you can crush in my couch as long as you want. Thanks.Christology
M
2

I see many reasons. My answer is not a generic solution but just adding yet another case that provide to that error. In my case it was setting a button's title like this:

button!.setTitleColor(.whiteColor(), forState: UIControlState.Normal)

instead of this:

button!.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
Magisterial answered 16/6, 2015 at 21:38 Comment(0)
H
1

In my case this error was caused by the incorrect (UTF8) .swift file encoding; Solved by copy-pasting the file's contents into a new file.

Headachy answered 3/4, 2015 at 10:21 Comment(0)
Y
0

change

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!  

TO

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

and do the same to others like this

Yehudi answered 11/9, 2014 at 0:15 Comment(3)
What do you mean other functions like this?Mudlark
Many Foundation functions with optional values has been changed. Find them out and update themYehudi
I've removed all the forced unwrappers of optionals (all exclamation points) from function definitions and my colleague and I am still getting this error. Any other ideas?Frizz
V
0

Go to the folder: Users/user/Library/Developer/Xcode/DerivedData

and clear all file,

then then clean and analyze,

It`s work to me.

Vorfeld answered 11/11, 2014 at 6:5 Comment(0)
W
0

I have the following code showing build error in Release.

if myValue > 5 { myValue = 5.0 }
if myValue < 0 { myValue = 0 }

Adding else between if statements fixed the issue:

if myValue > 5 { myValue = 5.0 }
else
if myValue < 0 { myValue = 0 }

Demo: https://github.com/exchangegroup/build-error-demo

Xcode Version 6.1 (6A1052d). Builds alright in debug. Submitted ticket to Apple Bug Reporter.

Wilser answered 5/12, 2014 at 4:48 Comment(0)
I
0

Just to put this out there: I get this error whenever I put [unowned self] in a block within a block, like this:

lazy var someVar: SomeType = {
    self.successBlock = {[unowned self] in
        // ...
    }
}()

The solution is to put the [unowned self] only at the topmost-level block. It seems an unowned reference to self is handled automatically for blocks within blocks.

Of course, I was only able to find this error by first finding out the troublesome file via @Maxwell's answer: https://mcmap.net/q/15844/-gm-release-of-xcode-6-compile

Imago answered 11/3, 2015 at 17:23 Comment(0)
G
0

To add my case here. I got the described error whenever I mark the closure with [unowned self], but never reference the self in the closure itself.

For example:

        request.startWithSuccess({ [unowned self] (req: CBRequest!, object: AnyObject!) -> Void in

            if let result = object["result"] as? [NSObject: AnyObject]
            {
                popup.type = result["email"] == nil ? AuthPopupType.Signup : AuthPopupType.Login
            }
            else
            {
                println("WARNING: Malformed response for kCBCheckUniquenesPath request.")
            }

            }, failure: { (req: CBRequest!, err: NSError!) -> Void in

                println("ERROR: Failure response for kCBCheckUniquenesPath request.")
        })
Goya answered 16/3, 2015 at 11:57 Comment(0)
N
0

By following @maxvel's suggestion, I got to know that max() and min() functions failed to compile in the release mode. I replaced it with my own functions like below.

//Swift compiler seems to failing to compile default min and max functions in release 
//mode hence writing my own
//
func maximum<T: Comparable> (one: T, other: T) -> T {
    if one > other {
        return one
    }
    else {
        return other
    }
}

func minimum<T: Comparable> (one: T, other: T) -> T {
    if one < other {
        return one
    }
    else {
        return other
    }
}
Nudi answered 20/3, 2015 at 7:11 Comment(0)
D
0

Maxwell's solution gives you the closest hint.

Dissertate answered 6/7, 2015 at 18:7 Comment(0)
M
0

Encounter this error when compiling this Swift 2.0 syntax in Xcode 6.4:

print(string, appendNewline: true);

Back to Xcode 7 and the error is gone.

Marylou answered 10/8, 2015 at 8:18 Comment(0)
B
0

In my case Xcode gave the error because of the following line :

if UI_USER_INTERFACE_IDIOM() ==  UIUserInterfaceIdiom.Phone {


}else {

}

And to fix the error I've defined this :

enum UIUserInterfaceIdiom : Int {
    case Unspecified
    case Phone // iPhone and iPod touch style UI
    case Pad // iPad style UI
}

And then i used it like :

 if UIDevice.currentDevice().userInterfaceIdiom == .Phone {

}

Good luck !

Blubbery answered 2/11, 2015 at 18:58 Comment(0)
A
0

I was also getting this error. I ran the the command in Terminal as suggested by @Maxwell and found out the error was in my GameViewController.swift file. A little digging around and found that it didn't like some auto-generated code or the code conflicted with a setting in Xcode somewhere

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

As soon as I removed this block the error went away.

Aiguille answered 8/11, 2015 at 18:10 Comment(0)
C
-2

I think the real problem is there are too many errors, so the compile tell you only a confused error code.

But you can always open the every source code file, in there you can find the detail error information and correct advice.

Good luck!

Caliche answered 16/9, 2014 at 7:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.