8

I updated my Xcode to Xcode 8 and accepted all the updates but I get an error telling me "Command failed due to signal: Segmentation fault: 11"

note that I am aware this question is very close to this one :

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

also note I am using a parse server, I doubt it has anything to do with it but I thought I will mention it in case.

but it hasn't solved my issue, has anyone had this issue / solved it ?

thanks !

Community
  • 1
  • 1
stephen D
  • 255
  • 1
  • 5
  • 16
  • try `cmd+alt+k` to clean build cache – Özgür Ersil Sep 28 '16 at 13:22
  • @ÖzgürErsil I tried this and it comes back – stephen D Sep 28 '16 at 13:27
  • 2
    it happens because of the third party pods you are using, try `pod update` after you clean your build cache – Özgür Ersil Sep 28 '16 at 13:28
  • This tends to happen with me when my project encounters lots of errors and can't cope. As mentioned elsewhere, the migration assistant won't do all the work for you, you'll likely have a lot of issues with your code to fix for the new syntax. Aside from @Ozgur Ersil's suggestion, you might also find it useful to add '-Xfrontend -debug-time-function-bodies' to the other flags section of Swift Compiler - Custom Flags which tells you how long each section of code is taking to compile. Aside from the well-advertised issues around dictionaries and arrays, watch out for bottlenecks around closures. – Marcus Sep 28 '16 at 13:29

5 Answers5

3

We encountered the same problem. This answer did solve our problem: Swift compiler segmentation fault when building

You have to unwrap all optionals before you can use them in a if statement.

Community
  • 1
  • 1
mbachm
  • 444
  • 5
  • 8
  • 1
    It does't seem that this is the problem here, I checked my code and it seems good, I don't even get the error on a specific line , it gives the error when I try to compile – stephen D Sep 30 '16 at 13:25
  • We got the error also only when we compiled our code. But if you did unwrap all optionals before, then this seems not to be the case. But do you have objective-c code in your project? With the new Xcode release some objective-c functions now return optionals which you don't see directly in Xcode – mbachm Oct 03 '16 at 12:01
  • I only use swift in my project so this isn't the problem – stephen D Oct 03 '16 at 12:31
  • not exactly the same problem for me but also related to optionals – toiavalle Apr 22 '17 at 05:01
3

This is a dynamic issue with Xcode but can be solved by modifying your own code in some way. It happened to me while I was migrating code from Swift2.3 to Swift3.1

In my case the error showed up at a method definition and the method is attached as an @IBAction for a UIButton.

@IBAction func changeButtonTapped(_ sender: AnyObject) {
    // some code
}

Changing the above code to following solved the seg-fault issue for me.

@IBAction func changeButtonTapped(_ sender: Any) {
    // some code
}

EDIT1: Another case of this segmentation fault came up.

This time it was due to redeclaring a variable in higher scope and using in the same if statement Example code:

// 'var1' is defined in higher scope
func someFunction() {
    if let var2 = var1,
       let var1 = someValue {
        // some code
    }
}

Xcode got confused as to which 'var1' named variable to use to define var2. Changing names to something else will solve the seg-fault.

Gursimran Singh
  • 301
  • 2
  • 5
0

Most likely cause is a coding error that XCode hasn't picked up because it's built-in analysis has crashed/isn't keeping up. Simply restarting XCode should show you where the error is in your code.

mm282
  • 453
  • 3
  • 7
0

In my case the error happens with code similar to this:

class AClass {
    var url: String?

    func aMethod() {
        guard let urlString = url, let url = URL(string: urlString) else {
            // Use `url`
        }
    }
}

Cause:

The fact that url is an optional instance var that I unwrap into itself, seems to crash the Swift compiler.

Locating the problem:

What's interesting and might give you a hint as to where the offending code is located, is that (at least in my case) the Xcode editor also crashes while you are writing the code:

enter image description here

Solution:

In my case, I just had to unwrap the optional instance var in another variable instead of itself (which was stupid in the first place...). E.g.:

class AClass {
    var url: String?

    func aMethod() {
        guard let urlString = url, let actualUrl = URL(string: urlString) else {
            // Use `actualUrl`
        }
    }
}
m_katsifarakis
  • 1,777
  • 1
  • 21
  • 27
-1

code with this error

let fileManager = FileManager.default
let fileAttributes = try! fileManager.attributesOfItem(atPath: OSWConfig.documentsPath.appendingPathComponent(folderName) as String) as NSDictionary

//below code cause the error

let createDate = fileAttributes.object(forKey: FileAttributeKey.creationDate)! as! NSDate

Correct code with no error

let keysList = fileAttributes.allKeys as! [FileAttributeKey]

let valuesList = fileAttributes.allValues

let indexCreateDate = keysList.index(of: FileAttributeKey.creationDate)! as Int

var createDate: NSDate!
if indexCreateDate >= 0 {
    createDate = valuesList[indexCreateDate] as! NSDate

}

This solved my issue.

Moennig
  • 1
  • 2