I'm getting the error ...
Command failed due to signal: Segmentation fault: 11
... when trying to compile my Swift app. I'm using Xcode 6.1, trying to build for an iPhone 5 on iOS 8.1.
My Code
import UIKitclass ViewController: UIViewController {@IBOutlet weak var username: UITextField!@IBAction func signIn(sender: AnyObject) {PFUser.logInWithUsernameInBackground(username.text, password:"mypass") {(user: PFUser!, error: NSError!) -> Void inif user != nil {println("Logged In")} else {func myMethod() {var user = PFUser()user.username = username.textuser.password = " "user.signUpInBackgroundWithBlock {(succeeded: Bool!, error: NSError!) -> Void inif error == nil {// Hooray! Let them use the app now.} else {println("Signed Up")}}}println(error)}}}override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.Parse.setApplicationId("key here")}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}}
And the error text!
CompileSwift normal arm64 /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swiftcd /Users/Alec/Desktop/Re-Chat/Re-Chat/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o0 swift 0x0000000108145a68 llvm::sys::PrintStackTrace(__sFILE*) + 401 swift 0x0000000108145f54 SignalHandler(int) + 4522 libsystem_platform.dylib 0x00007fff86631f1a _sigtramp + 263 libsystem_platform.dylib 0x00007fd0ac1eb010 _sigtramp + 6330493604 swift 0x00000001075d4517 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, llvm::ArrayRef<swift::Substitution>, swift::AnyFunctionRef) + 13035 swift 0x00000001075c599e swift::Lowering::SILGenFunction::visitFuncDecl(swift::FuncDecl*) + 1906 swift 0x000000010760987c swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 3807 swift 0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 1528 swift 0x000000010760a0a5 swift::Lowering::SILGenFunction::visitIfStmt(swift::IfStmt*) + 7579 swift 0x000000010760c8f6 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 16610 swift 0x00000001076097e8 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 23211 swift 0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 15212 swift 0x00000001075d52dd swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 20513 swift 0x00000001075b4234 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 19614 swift 0x00000001075eef71 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 9715 swift 0x00000001075e1866 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 287016 swift 0x00000001075e24da swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 605817 swift 0x00000001075cfa0b swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 23518 swift 0x00000001075ae824 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&) && + 19619 swift 0x0000000107604a69 swift::Lowering::RValueSource::materialize(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::SILType) && + 23320 swift 0x00000001075f371c swift::Lowering::SILGenFunction::emitInjectOptionalValueInto(swift::SILLocation, swift::Lowering::RValueSource&&, swift::SILValue, swift::Lowering::TypeLowering const&) + 26821 swift 0x00000001075e9b8d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 3644522 swift 0x00000001075e3e2b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1253923 swift 0x00000001075e202b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 485924 swift 0x00000001075cfab6 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 2225 swift 0x00000001075bffc4 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 83626 swift 0x00000001075bf582 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::RValueSource&&, swift::Lowering::AbstractionPattern) + 9827 swift 0x00000001075b7ff8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 112828 swift 0x00000001075b751a swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 5829 swift 0x00000001075e0d81 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 8130 swift 0x00000001075ea00d swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 23731 swift 0x0000000107609829 swift::Lowering::SILGenFunction::visitBraceStmt(swift::BraceStmt*) + 29732 swift 0x000000010760c8e8 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Stmt*) + 15233 swift 0x00000001075d4ee0 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 25634 swift 0x00000001075b3659 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 23335 swift 0x00000001075cea93 swift::ASTVisitor<SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 35536 swift 0x00000001075cd7eb SILGenType::emitType() + 20337 swift 0x00000001075c85ae swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 3038 swift 0x00000001075b555b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 39539 swift 0x00000001075b581a swift::SILModule::constructSIL(swift::Module*, swift::SourceFile*, swift::Optional<unsigned int>) + 31440 swift 0x00000001075b5968 swift::performSILGeneration(swift::SourceFile&, swift::Optional<unsigned int>) + 7241 swift 0x000000010748be18 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 343242 swift 0x000000010748996d main + 167743 libdyld.dylib 0x00007fff8aa4c5c9 start + 1Stack dump:0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/AppDelegate.swift -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -target-cpu cyclone -target-abi darwinpcs -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos -F /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat -g -import-objc-header /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/Re-Chat-Bridging-Header.h -module-cache-path /Users/Alec/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-generated-files.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-own-target-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-all-target-headers.hmap -Xcc -iquote -Xcc /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Re-Chat-project-headers.hmap -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Products/Debug-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources/arm64 -Xcc -I/Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/DerivedSources -Xcc -DDEBUG=1 -emit-module-doc-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name Re_Chat -emit-module-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.d -o /Users/Alec/Library/Developer/Xcode/DerivedData/Re-Chat-awwdkmqavitiqkcdsphwnhzhzzfb/Build/Intermediates/Re-Chat.build/Debug-iphoneos/Re-Chat.build/Objects-normal/arm64/ViewController.o 1. While emitting SIL for 'signIn' at /Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:14:152. While silgen closureexpr SIL function @_TFFC7Re_Chat14ViewController6signInFS0_FPSs9AnyObject_T_U_FTGSQCSo6PFUser_GSQCSo7NSError__T_ for expression at [/Users/Alec/Desktop/Re-Chat/Re-Chat/Re-Chat/ViewController.swift:16:80 - line:45:9] RangeText="{(user: PFUser!, error: NSError!) -> Void inif user != nil {// Do stuff after successful login.println("Logged In")} else {func myMethod() {var user = PFUser()user.username = username.textuser.password = ""// other fields can be set just like with PFObjectuser.signUpInBackgroundWithBlock {(succeeded: Bool!, error: NSError!) -> Void inif error == nil {// Hooray! Let them use the app now.} else {println("Signed Up")}}}println("error")}}"
Best Answer
You can get this error when the compiler gets too confused about what's going on in your code. I noticed you have a number of what appear to be functions nested within functions. You might try commenting out some of that at a time to see if the error goes away. That way you can zero in on the problem area. You can't use breakpoints because it's a compile time error, not a run time error.
I recently encountered the same problem, and I will try to generalise how I solved it, as a lot of these answers are to spesific to be of help to everyone.
1. First look at the bottom of the error message to identify the file and function which causes the segmentation fault.
2. Then I look at that function and commented out all of it. I compiled and it now worked. Then I removed the comments from parts of the function at a time, until I hit the line that was responsible for the error. After this I was able to fix it, and it all works. :)
For anyone else coming across this... I found the issue was caused by importing a custom framework, I have no idea how to correct it. But simply removing the import and any code referencing items from the framework fixes the issue.
(╯°□°)╯︵ ┻━┻
Hope this can save someone a few hours chasing down which line is causing the issue.
For me, this was caused by a change in the Parse SDK syntax in Swift 2.0. If you are using Parse and you upgrade to Swift 2.0, the following syntax changes:
Swift 1.2:
myPFQuery.findObjectsInBackgroundWithBlock({ (queryResults: [AnyObject]?, error: NSError?) -> Void in// CODE})
Swift 2.0:
myPFQuery.findObjectsInBackgroundWithBlock { (queryResults: [PFObject]?, error: NSError?) -> Void in// CODE}
The removal of the first '(' and the last ')' is what was causing the biggest problem. Took me AGES to find this!
I hit this error. After some frustration I tried Xcode clean and everything started working again. Just leaving this here for future reference.
For me this was caused by some of my code. The detailed compiler output in XCode actually pin-pointed the method where it was crashing.
I then commented out all the code in the method, made it return nil, and it did compile. I then re-implemented the method using different and much simpler code, and it worked.
I filed a bug report with Apple. This is the - admittedly somewhat crazy - code that caused the crash in XCode 7 / Swift 2.0.
func numberAndTitleFromDirectoryName(dirName: String) -> (Int, String)? {let components = dirName.characters.split(maxSplit: 1, allowEmptySlices: false) { $0 == " " }.map { String($0) }.map { String($0) }if let number = components.first?.toInt() {if let title = components.last {return (number, title)}}return nil;}
I guess I got a little over-excited using the map function there... The new version is a lot simpler and also more human comprehensible. Still the compiler shouldn't crash. At worst it should show some errors. The code as is worked in Swift 1.x
When I got this error converting from Swift to Swift 2.0, it clearly indicates a particular file (blahClass.swift) that has the problem, then it outlined all of the warnings & errors in the error message text. I went through and resolved these manually and now the app compiles fine.
object.doubleValue = dict["doublevalue"] as! Int
I found the reason after rolling back each step I made.... force casting to Int for a Double variable
Easy fix if using git.
1) In terminal:
git stash
2) Seg fault disappears.
3) Run the app.
4) In terminal:
git stash pop
5) Xcode now tells you the real problem.
I had similar issue in with Xcode 7.3 and iOS 9.3.Command failed due to signal: Segmentation fault: 11
Basic steps such as Clean (cmd+shift+k) code, Delete derived data and Quit Xcode didn't work.
There was some culprit in my code.
It was [txtUserName.text.characters.count = 0]
In your case Review your code and fix the culprit.
One of case, is that you have named datatype of getter variable like its name.For example:
var someInstance: someInstance {...
Update #1.Keep attention on _a variable which isn't Int, and you forget to point right return type. Issue happens in more than two operands of infix operator.
function getInt(value: Int) -> Int {return _a? ?? _b?.count ?? 0}
Any crash is a compiler bug (whether or not your code is valid). Try the latest beta and if it still crashes file a bug report at bugs.swift.org. The Swift team are very responsive on these.
I got rid of this error by following.
I had many frameworks added in "Link Binary With Libraries" and was using a bridging header as well.
I re-added all the frameworks and added the bridging header again. This solved my issue.
I'm using Xcode 8.3/Swift 3
I used @Ron B.'s answer to go through all the code and comment out different functions until I got a successful build. It turns out it was async trailing closures
that was causing my error:
My trailing closures:
let firstTask = DispatchWorkItem{//self.doSomthing()}let secondTask = DispatchWorkItem{//self.doSomthingElse()}//trailing closure #1DispatchQueue.main.asyncAfter(deadline: .now() + 10){firstTask}//trailing closure #2 DispatchQueue.main.asyncAfter(deadline: .now() + 20){secondTask}
Once I used the autocomplete syntax the Segmentation fault: 11
was Gone
//autocomplete syntax closure #1DispatchQueue.main.asyncAfter(deadline: .now() + 10, execute: firstTask)//autocomplete syntax closure #2DispatchQueue.main.asyncAfter(deadline: .now() + 20, execute: secondTask)
I have same problem so I tried switch Optimization Level to Fast, Single-File Optimization[-O] instead of Fast, Whole Module Optimization then it worked, built, archive to Appstore succeed.
Some frameworks we used that need to refactor to adapt with Fast, Whole Module Optimization level I think.But I still did not find those framework.
In my case this happened in Xcode 11 beta 3 with Swift 5 and using SwiftUI.
My View has a @State property like this:
@State private var normInfo: NormInfo?
the issue got solved by explicitly initializing it with nil
.
I had that code 11 when trying to build for release scheme. It pointed out one viewcontroller class (swift) that had this piece of code inside:
required init(coder aDecoder: NSCoder) {super.init(coder: aDecoder)stuff...}
The problem was that when I have added superclass to it, I forgot to also implement init. So that super.init caused compiler error Segmentation fault: 11So if you have such problem it's good idea to check also any superclasses.
I also had the Segmentation Fault 11, when importing a framework made by myself (yeah, felt really dumb).
After developing the framework for months and integrating it into a main project with intermixed Obj-C and Swift, importing to Obj-C was a no-problem, but as soon as I wrote the import MySwiftProject
in Swift, all hell broke loose.
Long story short, the problem was that I created some custom methods that provide typification for NSNotifications
using closures, for example:
func post(a : Int, b : String){NSNotificationCenter.defaultCenter().postNotification("notification", object: nil, userInfo: ["a" : a, "b" : b])}func observe(block : (a : Int, b : String) -> ()) -> NSObjectProtocol{return NSNotificationCenter.defaultCenter().addObserverForName("notification", object: nil, queue: nil){(n : NSNotification!) -> () in// Unwrap the notification payload and provide typesif let a = n.userInfo?["a"] as? Int, let b = n.userInfo?["b"] as? String{block(a, b)}}}
(Actually, the code above I did with a template, but that's another story)
The main culprit? This:
func ... -> NSObjectProtocol
Apparently, Apple can use NSObjectProtocol
in the declaration of NSNotification
's methods, but when I do, it introduces a Segfault 11
. Replacing NSObjectProtocol
to AnyObject
solved the crash.
Unfortunately, this might not solve your issue, since segfault 11 is simply a generic crash of the compiler, but you can take steps to solve it. It took me around 2 hours, but this is what I did:
- Create a new project, replicating the structure you had. In my case, I created a single view controller swift project, and added a swift framework inside as another project.
- Copy all the original code from one to another.
- Go to the compilation phase, and start removing files to compile, try disabling pieces of code that are very swift-hacky (like my NSNotification typification).
- Every time you do a change, do a clean (⌘⌥ ⇧ +K), build (⌘+B) and fix any errors.
- Repeat from 3 until the segmentation fault goes away.
In my case the reason was having a class declared within another class within an extension.
extension classOrig {class classChild {class classGrandChild {static let aVariable : String = "SomeValue";}}}
This generated the error on my side. I had several frameworks in my project, yet it did not happen before.
I also struggled with this for a while. I upgraded my code to Swift 2 with Xcode 7.2 and for me the problem was this:
self.mainScrollView.documentView!.subviews.reverse() as! [MainSubView]
Which I had to change to:
(self.mainScrollView.documentView!.subviews as! [MainSubView]).reverse()
I got this error when I was overriding a property in a subclass and I didn't repeat the property's declaration exactly.
Base class:
var foo: String! {return nil}
Subclass:
override var foo: String {return "bar"} // missing the implicit unwrap operator
For me it's because I have two bundles with the same name.
Read the debug message carefully.
in my case, I encountered this error because I used a single '=' instead of double '=' by mistake in if-statement.
if aString.characters.count = 2 {...}
None of these answers worked for me but I found my issue. It had to do with Error Handling (in the Disabling Error Propagation section). I had this method:
func getSlider() throws -> UISlider {... // code that could throw an errorreturn UISlider()}
Referencing it like this:
func anotherMethod() -> Float {return try! getSlider().value}
gave the error. But, when switching to this, it went away:
func anotherMethod() -> Float {return (try! getSlider()).value}
I also ran into this problem.... obviously, it is a general error or sorts... when the xcode gets confused.... in my case, I had 3 vars that I was assigning values to from an array.... but I did not specify the type of data in each element of the array.... once I did, it resolved the problem....
In my case I had declared the following property in one of my ViewControllers subclass:
@property NSString * title
I think this was conflicting with the already existing title
property in ViewController
. I renamed this property to something else and refactored its use and the error disappeared.
In my case it was caused by trying to use a function that returned an NSNumber as an argument where a Double was expected. My advice is be careful mixing Objective C objects with Swift datatypes. And as many others have suggested, comment out lines until you pinpoint which one causes the error. (Even if you create other errors when doing so, you can just ignore them and see what makes the segmentation fault error go away.)
For me I was blocking the main thread.
What I did to Fix it with GCD (see below)
dispatch_async(dispatch_get_main_queue(), })
Human Error report:
In my case, the culprit was passing in an array in the place of a variadic parameter. That is, for the signature:
// Note the variadic parameterfunc addSubview(subview subview: UIView, constrain: NSLayoutAttribute...)
I passed in:
// Compile-time error, "constrain" parameters have array bracketssomeUIView.addSubview(subview: someOtherView, constrain: [.Leading, .Top, .Bottom, .Trailing])
rather than:
// CorrectsomeUIView.addSubview(subview: someOtherView, constrain: .Leading, .Top, .Bottom, .Trailing)
I got segmentation fault on my Mac Mini using Xcode Bots. The seg fault did only occur during build step of testing and not during building or running locally. Only in Xcode bots during build step of testing.
I am using macOS Sierra and Xcode 8, with the code converted to Swift 2.3.
I finally found the line causing the seg fault, it was caused by:
public let isIpad = UIDevice.currentDevice().userInterfaceIdiom == .Pad
Which was declared outside a class as a constant. Changing it to check the userInterfaceIdiom at runtime fixed the issue.
Hopes this helps someone else!
This is the error log for my seg fault:
0 swift 0x000000010f93d76b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 431 swift 0x000000010f93ca56 llvm::sys::RunSignalHandlers() + 702 swift 0x000000010f93ddbf SignalHandler(int) + 2873 libsystem_platform.dylib 0x00007fffb24aabba _sigtramp + 264 libsystem_platform.dylib 0x00007fbbfff49ae0 _sigtramp + 13029824645 swift 0x000000010db79996 (anonymous namespace)::Traversal::visit(swift::Expr*) + 1186 swift 0x000000010db7b880 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 1287 swift 0x000000010db799eb (anonymous namespace)::Traversal::visit(swift::Expr*) + 2038 swift 0x000000010db78f45 swift::Expr::walk(swift::ASTWalker&) + 539 swift 0x000000010d6d2c87 walkForProfiling(swift::AbstractFunctionDecl*, swift::ASTWalker&) + 23110 swift 0x000000010d6d2719 swift::Lowering::SILGenProfiling::assignRegionCounters(swift::AbstractFunctionDecl*) + 55311 swift 0x000000010d6de348 (anonymous namespace)::SILGenType::emitType() + 95212 swift 0x000000010d6ddf1e swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 3013 swift 0x000000010d6625eb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 73114 swift 0x000000010d663139 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 79315 swift 0x000000010d6635a3 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 11516 swift 0x000000010d491c18 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 1253617 swift 0x000000010d48dc79 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 277718 swift 0x000000010d489765 main + 195719 libdyld.dylib 0x00007fffb229e255 start + 1