michalronin
michalronin

Reputation: 243

Command failed due to signal: Segmentation fault: 11 | Xcode 7.2

I was asked to migrate a rather large app to Swift 2. The compiler keeps throwing segmentation fault: 11 errors for one function, present in different modules of the app's logic (only difference being variables used):

func loadMoreContent() {

if let collection = self.ratingsCollection where collection.identifier != 0,
  let totalEntries = collection.totalEntries,
  let objects = self.ratings?.count where objects < totalEntries {

    self.ratingsCollection = nil

    collection.nextPage().onSuccess { (value) in

      if let collection = value as? Collection<Rating> {
        self.ratingsCollection = collection
      } else {
        self.ratingsCollection = Collection<Rating>(identifier: 0)
      }

      }.onFailure { error in
        self.ratingsCollection = Collection<Rating>(identifier: 0)
    }
  }
}

Here are the errors themselves:

1.  While type-checking 'loadMoreContent' at (path redacted).swift:46:3
2.  While type-checking expression at [(path redacted).swift:54:9 - line:64:9] 
    RangeText="collection.nextPage().onSuccess { (value) in

              if let collection = value as? Collection<Rating> {
                self.ratingsCollection = collection
              } else {
                self.ratingsCollection = Collection<Rating>(identifier: 0)
              }

              }.onFailure { error in
                self.ratingsCollection = Collection<Rating>(identifier: 0)
            }"

3.  While loading members for declaration 0x7fdda42ea2b0 at <invalid loc>
4.  While deserializing 'producer' (FuncDecl #340) 

Does anyone have any idea what can be wrong with this function at first glance? I should add it compiles with no changes in Xcode 6 / Swift 1.2.

Upvotes: 4

Views: 2868

Answers (1)

WaterNotWords
WaterNotWords

Reputation: 1007

This is a hair pulling error especially common in XCode7.

Occasionally the usual XCode stupid bug protocol (clean, XCode Restart, clean, build) fixes it. However, often it is due to one or more offending lines of code. This doesn't necessarily mean there is a bug in the code, either!

So, before restarting, it is sometimes useful to undo recent changes sequentially and trying to build as you go along. If any of your dependencies or frameworks have been updated since your last successful build, these could be a likely candidate.

There are a couple things that seem to produce this error fairly regularly. So please add to this list concisely if you can isolate specific issues that CONSISTENTLY cause errors for you:

1) String concatenation using the plus operator in calls to methods that use autoclosures (found in calls to XCGLogger):

 public func myFunc(@autoclosure closure: () -> String?){
      // do something
 }

 someInstance.myFunc("Hi " + nameStr + "!")

2) failure to call super.init() from subclass especially when super class is using a default initializer (you haven't explicitly created your own init)

3) Accidentally using a single equals sign to test for equality (using = instead of == ) especially in complex statement such as in this answer.

Upvotes: 3

Related Questions