Chirila Vasile
Chirila Vasile

Reputation: 359

Xcode 7 compile error : "Command failed due to signal: Segmentation fault: 11"

Yesterday I installed the official Xcode 7 and when I tried to open one of my Swift projects, appeared an alert saying that the new Xcode version wants to update my swift code (or something like this). Okay, I accepted and after this appeared "Command failed due to signal: Segmentation fault: 11" compile error (if you want details about this, I can write the whole error text). Anyone have the same issue?

Thanks

Edited

I installed back Xcode 6.4 and it's okay, no compilation errors.

Upvotes: 24

Views: 31305

Answers (25)

technerd
technerd

Reputation: 14504

I have face this problem many time while converting various projects to Swift3.0.

As this issue looks dynamic, every one has its own solution other then any universal answer. But in this issue main problem is to identify spot to get work on. So What I am following is as below:

  • Identify method which one is responsible for error

    Click on Error Message

enter image description here

  • Here you will identify class which responsible for error to generate compile time error

    enter image description here

In my case AppDelegate is responsible.

  • To find line of error, go to end of long error description.You will find code something like below:

    1. While emitting IR SIL function @_TFC9MyProject11AppDelegate21getNotificationDetailfGSqGVs10DictionaryVs11AnyHashableP___T_ for 'getNotificationDetail' at /Users/ABC/Documents/BitBucket/iOS/2016/Projects/MyProject/AppDelegate/AppDelegate.swift:153:5

Here 153 is line of code in AppDelegate.swift.

func getNotificationDetail(_ launchOptions : [AnyHashable: Any]?) {
    if launchOptions != nil {
        let dictLaunch = launchOptions! as NSDictionary
        NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.openRespectiveNotificationScreen), name: NSNotification.Name(rawValue: WebServiceKey.APPMANAGER_SERVICE_CALL_FINISH), object: nil)

        inactiveUserInfo  = dictLaunch.object(forKey: UIApplicationLaunchOptionsKey.remoteNotification) as? NSDictionary
    }
}

Then comment all the code inside method and build again. Then try uncomment one by one line ,so you finally get line which generates error.

After finding exact line of code, you can easily fix it.

In my code i find last line of this method generate error.

So i replace it with below code and it build get successfully.

inactiveUserInfo  = dictLaunch[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary

So main thing is to debug cautiously. Try this way, you will definitely solve error easily.

Upvotes: 4

dave
dave

Reputation: 1587

For me, the problem (XCode 7.3.1) was using a += operator on a dictionary item.

for example:

func test() {
    var myDict:[String:String] = [:]
    myDict["key"] = "pig"
    myDict["key"] += "dog"

    var myArray:[String] = []
    myArray.append("pig")
    myArray[0] += "dog"
 }

This will cause a segmentation fault. Remove the += on myDict, and all is ok.

I am aware this is a bug (dictionary references are nullable) but the compiler should not crap out like this.

Upvotes: 1

Isaac
Isaac

Reputation: 1890

In my case, the cast I had to correct was similar to Murat Yasar answer ( https://stackoverflow.com/a/36867502/512403 ), but mine had two parts to correct. The compiler didn't work with the original fix, so I had to tweak my code still a bit more:

Bad version:

let jsonObject: AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments)

Good version:

let jsonObject = try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! [String: AnyObject]

Maybe this can help someone new to these quirks of Swift.

Upvotes: 0

Dana Wheeler
Dana Wheeler

Reputation: 64

I received this error when attempting to compile with Xcode 8.2.1. I am using Cocoa Pods and suspected one of the pods was the issue, as some of the pod's files were referenced in the lengthy error output from the compiler. After quitting Xcode and running pod update in my project directory (via Terminal), I was able to compile successfully when I re-opened my project.

Upvotes: 0

RawKnee
RawKnee

Reputation: 323

I have a project that it happens in the same file from time to time. My workaround is :

Go to the file that the segmentation fault mentioned, comment out all imports, run (Build fails obviously), uncomment all imports -> Builds successfully.

My imports were Firebase and FirebaseAuth if it helps anyone.

Upvotes: 0

Max Chuquimia
Max Chuquimia

Reputation: 7824

For me, this was caused by declaring a struct in a final class' extension:

final class X {
    ...
} 

extension X {
    struct Y {
        ...
    }
}

Upvotes: 0

ReshDev
ReshDev

Reputation: 83

Here is how i fixed - first as suggested by many here, please read the log carefully. It actually tells you exactly the line number where it is failing and why it is failing. Just commenting that line out fixed the issue. In my case it was a type checking error. I am using Gloss structs for JSON parsing and it appears that as you go deeper in the JSON hierarchy sometimes the in-line parser does not recognise that there is a compile time issue. When you build the project it fails. Ideally type checking error should be recognised by the in-line parser. So this may be an issue with Xcode but its your code that is breaking it. When I read many of the posts - my analysis as follows.. root cause is related to type checking. When you are trying to assign incorrect types (optional or otherwise) and in-line parser does not recognise it in some instances. When you build it does recognise it and causes segmentation error. Its our code thats wrong despite a bug with Xcode it can be fixed if we read the logs carefully!

Upvotes: 0

Hailong
Hailong

Reputation: 1094

For me:

I use Closure as AnyObject, after I use this Cast closures/blocks function. Error solved.

typealias UserCallBack = () -> Void
...
if let callBack = callBack as? AnyObject {
  request?.userInfo["callBack"] = callBack
}

Upvotes: 0

Chris Gunawardena
Chris Gunawardena

Reputation: 6468

For me it was a lengthy function that contained test data array.

Upvotes: 0

claassenApps
claassenApps

Reputation: 1147

For me, the problem was changing how I check if something was false. Instead of:

if object1.hidden == false {
}

change to:

if object1.hidden != true {
}

Upvotes: 0

Murat Yasar
Murat Yasar

Reputation: 1044

Omg, this is a terrific bug of Xcode. Just read this. http://blog.bellebethcooper.com/xcode-bug.html It made me smile.

The change was deceptively small, but here's what it was (inside my API client class, where I actually get the JSON data from the API):

I changed this:

`let json = try? NSJSONSerialization.JSONObjectWithData(data, options: [])`

to this:

`let json = try? NSJSONSerialization.JSONObjectWithData(data, options: []) as! [String: AnyObject]`

This is one of the most frustrating debugging experiences I've ever had, but I hope this post might help someone else who has the same issue. And if you ended up here via googling a bug you're struggling with and this didn't help you, I'm so sorry. I know exactly what you're going through. Don't give up!

Upvotes: 11

KrishnaCA
KrishnaCA

Reputation: 5695

I faced this compilation error in Xcode Version 7.3 (7D175), swift project. The following is the scenario:

  1. Declared "@objc protocol" in swift class
  2. In another class that implements this protocol, one of the non-optional methods is not implemented

Implementing the method solved the problem for me. This might be one of the reasons for people facing this problem. I hope that this helps

Upvotes: 1

Kyle KIM
Kyle KIM

Reputation: 1431

Read the debug message carefully.

I encountered this error because I used a single '=' instead of double '=' by mistake in if-statement.

if aString.characters.count = 2 {...}

Upvotes: 2

Kevin
Kevin

Reputation: 1903

I was trying to make use of ?? in a clever way when this happened to me.

I guess swift does not like when you try to chain multiple ?? together as in, though the syntax highlighter doesn't throw any error:

let ageNum = self.ageValue > 0 ?? self.birthday?.ageFromDate() ?? 0

Upvotes: 0

Juan Valera
Juan Valera

Reputation: 139

I had the same problem. Xcode 7.2.1. And selecting the error and expanding the logs I could find the compile error buried among the long paths.

See the line after the "1." in the attached image. It has a reference to a file and a line. Looking at it I could find the error.

In my case, I had an invalid enumeration assignment, I moved some logic from a struct to an enumeration and injected this error:

I had:

return .Success(dict: dict)

I should have:

return .Success(dict)

Log error after selecting it in the Issue Navigator

Upvotes: 1

Mitsuaki Ishimoto
Mitsuaki Ishimoto

Reputation: 3181

At first, I recommend to watch the build log carefully to find the file having problems. In my case, an optional value used in for loop caused Segmentation fault on the build process.

for i in 0..<hoge?.count {

I fixed my code like following;

for i in 0..<hoge!.count {

I have no error now. \(^o^)/

Upvotes: 3

SHS
SHS

Reputation: 1412

I was trying to write the NSData to file as following code.

 if let currentResumeData = currentUserInfo["NSURLSessionDownloadTaskResumeData"]
 {
     // the following "do" was giving the above mentioned compile error.
     do {
         try currentResumeData.writeToFile(fileNameString, options: .DataWritingAtomic)
     } catch {}
     // the above error code.
 }

After reading various answers on StackOverflow, I changed it as under, which removed the error.

 if let currentResumeData:NSData = currentUserInfo["NSURLSessionDownloadTaskResumeData"] as? NSData {
 {
     do {
         try currentResumeData.writeToFile(fileNameString, options: .DataWritingAtomic)
     } catch {}
 }

As you can see, compiler required proper NSData type of variable "currentResumeData" to call it's method .writeToFile.

I am sure, this will be helpful to others.

Upvotes: 0

Muhammad Umair
Muhammad Umair

Reputation: 1714

This indicates that some Required method/func is missing from your code. In my case I was using ObjectMapper and in my class I was forgot to include required init() method which causes this "Command failed due to signal: Segmentation fault: 11"

required init?(_ map: Map) {

}

Upvotes: 7

Chirila Vasile
Chirila Vasile

Reputation: 359

The error disappeared at the same time with the next version of Xcode. After some research on apple forums, there was a bug with that version of the "best" IDE ever, Xcode. Hopes that all the answers helped someone.

Upvotes: -1

user2084611
user2084611

Reputation: 450

Restart xcode. Clean build (cmd+k, cmd+shift+k and clean build folder -> option+cmd+shift+k) It should fix the problem.

Upvotes: 0

Manuel
Manuel

Reputation: 15042

I had the same error because of:

 let stringB: String? = stringA.characters.count = 0 ? nil : stringA

Solution was to change it to:

 let stringB: String? = stringA.characters.count > 0 ? stringA : nil

Maybe this helps someone...

Upvotes: 1

PerfectGamesOnline.com
PerfectGamesOnline.com

Reputation: 1778

Look at the other warning you see around.

My case pointed me to problem with iOS9 and GoogleAds. See here: https://developers.google.com/admob/ios/ios9

Short answer was to disable build setting ENABLE_BITCODE.

My error:

ld: '/pp/src/shared_js/libs/GoogleMobileAdsSdkiOS-7.3.1/GoogleMobileAds.framework/GoogleMobileAds(GADGestureIdUtil.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture armv7
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)

Upvotes: 6

Erik Auranaune
Erik Auranaune

Reputation: 1414

I had the same error in my project after upgrading to xCode 7. I decided to remove the new version of xCode and install xCode 6.4. After all, it worked fine using xCode 6.4, so i suggest you do that to start with. On other hands, you should always be up to date, but you can also have both xCode 6.4 and 7.0 :) Hope this works out for you!

Upvotes: 0

Adriana Pineda
Adriana Pineda

Reputation: 9480

Did you try re-opening the project and/or re-adding your scheme? I did it and the error was gone.

Upvotes: 0

ios killers
ios killers

Reputation: 109

unfortunately, I always has the same error as you are. I suggest the best way for you is recreating an new project by new Xcode and the transplant all the code to this new project, the problem will solve. By the way, after updating any place like framework or xcode, this error may be occur, the apple is stupid.

Upvotes: 0

Related Questions