24

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.

Chirila Vasile
  • 359
  • 1
  • 2
  • 11

25 Answers25

11

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!

Murat Yasar
  • 994
  • 9
  • 24
  • 1
    I had this issue dealing with JSON but it was referencing the data using numerous multi-level dictionary references that caused the issue for me. The same code also crashed the syntax highlighting too (often a sign of trouble). I was saying (something like): funcCall(data!["address"]!["street_address"] as String, data!["address"]!["locality"] as String, etc, etc, etc). I just removed the multi-level dictionary references when accessing the data and both issues cleared up. – RowanPD May 24 '16 at 15:09
  • A pro tip for debugging: check too long variable names and too long commands. – Murat Yasar Aug 10 '17 at 14:50
7

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

}
Muhammad Umair
  • 1,664
  • 2
  • 20
  • 28
6

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)
PerfectGamesOnline.com
  • 1,774
  • 1
  • 18
  • 31
  • This was the right direction for me but I had to do it a couple of times. NO Clean Build...YES Clean Build. Worked in my case. – Edison Jul 09 '16 at 23:43
4

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.

technerd
  • 14,144
  • 10
  • 61
  • 92
3

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^)/

Mitsuaki Ishimoto
  • 3,162
  • 2
  • 25
  • 32
  • Xcode 7.3 cannot compile this code with the error of Segmentation fault. Previous version can do. I indicate that this problem is based on code and the cause can be found by checking the build log. – Mitsuaki Ishimoto Apr 02 '16 at 14:16
2

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 {...}
Kyle KIM
  • 1,384
  • 2
  • 15
  • 31
  • Read the debug message carefully. - Exactly! While Error message is just "Command failed due to signal: Segmentation fault: 11", the reason is hidden in collapsed log message. Strange that Xcode doesn't display it in correct manner. – brigadir Jul 25 '16 at 18:31
1

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

Manuel
  • 14,274
  • 6
  • 57
  • 130
1

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

Juan Valera
  • 139
  • 5
1

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

KrishnaCA
  • 5,615
  • 1
  • 21
  • 31
1

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.

hkutluay
  • 6,794
  • 2
  • 33
  • 53
dave
  • 1,567
  • 2
  • 21
  • 34
0

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.

ios killers
  • 109
  • 1
  • 1
  • 3
  • 1
    Recreating a new project will take some time because i am using third-party frameworks and it's not worth it. Yes, apple is stupid ! – Chirila Vasile Sep 28 '15 at 05:26
0

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

Adriana Pineda
  • 9,219
  • 1
  • 12
  • 14
0

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!

Erik Auranaune
  • 1,384
  • 1
  • 12
  • 27
0

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

user2084611
  • 450
  • 3
  • 8
  • Aah ok. But it works for many of us. Anyways try other options then. Last resort I would try is restarting mac itself. It many times helped me fixing unknown issues either due to references or XCode bugs. – user2084611 Mar 19 '16 at 00:49
  • Restart ended up being the fix. Thanks! It was happening in all of my projects so I figured it was a bigger problem than a line of code. – Aaron Mar 19 '16 at 05:22
0

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.

SHS
  • 1,414
  • 4
  • 26
  • 43
0

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
Kevin
  • 1,883
  • 16
  • 23
0

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 {
}
claassenApps
  • 1,137
  • 7
  • 14
0

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

Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
0

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
}
Community
  • 1
  • 1
Hailong
  • 1,084
  • 10
  • 9
0

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!

ReshDev
  • 83
  • 8
0

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

final class X {
    ...
} 

extension X {
    struct Y {
        ...
    }
}
Max Chuquimia
  • 7,494
  • 2
  • 40
  • 59
0

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.

RawKnee
  • 324
  • 3
  • 11
0

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.

Dana Wheeler
  • 64
  • 2
  • 4
0

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.

Community
  • 1
  • 1
Isaac
  • 1,794
  • 4
  • 21
  • 41
-1

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.

Chirila Vasile
  • 359
  • 1
  • 2
  • 11