Command failed due to signal: Abort trap: 6

SwiftXcode

Swift Problem Overview


Since Xcode 7 and Swift 2.0, I get the error above, like in the screenshot shown here:

screenshot of error log

I have no idea where this is coming from, cleaning and deleting derived data didn't work.

Anyone else experiencing this problem?

Project settings:

project settings

Target settings:

target settings

Swift Solutions


Solution 1 - Swift

I faced this issue when used the same constant names in a guard construction

let activityVC = ...
        
guard let activityVC = activityVC else { return }

But xcode didn't show me any warning for this row.

Solution 2 - Swift

Go to project Build settings -> Swift Compiler - code generation -> Optimization Level -> For both Debug & Release select option "Fast,Single-File Optimization[-O]

enter image description here

Solution 3 - Swift

I have the same problem with all Xcode 6.3 projects, I open in Xcode 7.0. I created a new project, copied all my source files and resources and everything worked without this compiler error. I thought this has something to do with the project settings. I turned off the Swift compile Optimization to "none" and the Trap 6 was gone away. Perhaps there are other settings, which also generate trouble, but for me this it was.

Solution 4 - Swift

This worked for me, so just give it a try. i got this error while converting the code from swift 3 to swift 4.

Simply, go to Project>Target>Build Setting and search 'Swift Compiler - Code Generation' and set Optimization level to 'No Optimization[-Onone]'.

Solution 5 - Swift

In my case

Error

override func observeValueForKeyPath(keyPath: (String!)?, ofObject object: (AnyObject!)?, change: ([NSObject : AnyObject]!)?, context: UnsafeMutablePointer<Void>)

Ok

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [NSObject : AnyObject]?, context: UnsafeMutablePointer<Void>)

Solution 6 - Swift

I got this error too on XCode 7 Beta 5. After I clean the build, then I got another error saying one of my class not conforming to the protocol I just changed. After I fix the issue, it builds. The protocol changes I made is to change two parameter type of a method from Int to Int32

Solution 7 - Swift

In my case,

The compiler would give me the message:

Incorrect number of arguments passed to called function!
%4 = call %swift.type* @_T015SimplifiedCoder6StructVMa() #1, !dbg !3112
<unknown>:0: error: fatal error encountered during compilation; please
file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!

but I realized that I missed a default generic parameter:

class Class<K> {
    init<T: Protocol>(_ value: T) where T.Key == K {}
}

protocol Protocol {
    associatedtype Key
    static func getClass<NewKey>(_: NewKey.Type) -> Class<NewKey>
}

struct Struct<K>: Protocol {

    typealias Key = K

    static func getClass<NewKey>(_: NewKey.Type) -> Class<NewKey> {
        let _self = Struct<NewKey>()
        return Class(_self)
    }
}

protocol CanGetClass {
    associatedtype StructType: Protocol
}

extension CanGetClass {
    func getClass<Key>(_: Key.Type) -> Class<Key> {
        return StructType.getClass(Key.self)
    }
}

struct R: CanGetClass {
    typealias StructType = Struct
}

changed:

typealias StructType = Struct

to:

typealias StructType = Struct<Int>

the extension of CanGetClass tried to call getClass on an incomplete type.

Solution 8 - Swift

I received this when did that:

protocol ProtocolA {
    associatedtype BType: ProtocolB
}

protocol ProtocolB {
    associatedtype AType: ProtocolA
}

Solution 9 - Swift

Make sure you don't implement a private protocol into class extension. Most of the time would be quite strange to have a private protocol, but not necessary, depending on what you wish to encapsulate.

Something like, in the same file:

class C: ... {
}

extension C: P {
}

private protocol P: class {
}

Do this an you'll surely get Command failed due to signal: Abort trap: 6

Instead remove the private modifier from the protocol and the error is fixed.

Solution 10 - Swift

I got this error when attempting to run tests. To solve it, I put this script into Terminal:

rm -rf ~/Library/Developer/Xcode/DerivedData

Deleting derived data resolved the issue

Solution 11 - Swift

I was able to resolve it by making a change to the bridging header. In my case adding a line break was sufficient. Very strange bug.

Solution 12 - Swift

I made mistake of using similar constant "name" in guard statement, causing this error.

guard let model = DataModel(JSON: response),
      let model = model.first else { return }

In above example, constant name "model" is used twice, use new constant name instead.

guard let parsedObj = DataModel(JSON: response),
      let model = parsedObj.first else { return }

NOTE: Xcode compiler do not warn you on this in compilation.

Please also check this answer which help to identify cause of this error. https://stackoverflow.com/a/67620285/5433935

Solution 13 - Swift

My code was crashing because of nested function. Example code is below :

Error :

extension UILabel {
    
    var attributedTextTruncates: Bool {
        
        guard numberOfLines > 0 else { return false }
        return countLabelLines() > numberOfLines
        
        func countLabelLines() -> Int {
            guard let myText = attributedText else {return 0}
            
            let labelSize = myText.boundingRect(with: CGSize(width: self.bounds.width, height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, context: nil)
            return Int(ceil(CGFloat(labelSize.height) / self.font.lineHeight))
        }
    }
}

Correct Code :

extension UILabel {
    
    var attributedTextTruncates: Bool {
        guard numberOfLines > 0 else { return false }
        return countLabelLines() > numberOfLines
    }
    
    private func countLabelLines() -> Int {
        guard let myText = attributedText else {return 0}
        let labelSize = myText.boundingRect(with: CGSize(width: self.bounds.width, height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, context: nil)
        return Int(ceil(CGFloat(labelSize.height) / self.font.lineHeight))
    }
}

Solution 14 - Swift

In my case, it was with setting a value to a parameter in a function to nil that was causing the error.

Before:

public func comparableValidator<T: Comparable>(minValue : T? = nil, maxValue : T? = nil, value: T) -> Void {
    if let min = minValue {
        _assertFunc(min <= value, "\(value) must be at least \(min)")
    }

    if let max = maxValue {
        _assertFunc(max >= value, "\(value) must be at most \(max)")
    }
}

After:

public func comparableValidator<T: Comparable>(minValue : T?, maxValue : T?, value: T) -> Void {
    if let min = minValue {
        _assertFunc(min <= value, "\(value) must be at least \(min)")
    }
    
    if let max = maxValue {
        _assertFunc(max >= value, "\(value) must be at most \(max)")
    }
}

Solution 15 - Swift

I am able to reproduce this simply and consistently with a brand-new project created in Xcode 7.0 beta (7A120f). Note that the problem is likely more broad than the example, but this is 100% reproducible for me by only adding a single line to a new project. This problem also appears to exclusively apply to iOS, not OS X, at least for this example. Have submitted bug report # 21376523 to Apple.

  1. Create a brand-new project in Xcode 7.0 (7A120f). Type is "Game", Language is "Swift", Game Technology is "SceneKit".

  2. Build and run with default settings. Project builds and runs fine in simulator (you will see the default rotating 3D spaceship model).

  3. Add a single SCNVector3 property to GameViewController.swift, like this:

     class GameViewController: UIViewController {  
       var p = SCNVector3Zero  
    

--> Produces "Abort trap: 6". Project will no longer compile.

  1. Change the constant to an empty initializer.

     class GameViewController: UIViewController {  
       var p = SCNVector3()  
    

--> Same problem, "Abort trap: 6"

  1. Remove property, restoring to the clean project state.

--> "Abort trap: 6" is gone, project again compiles and runs.

  1. Change "var" to "let".

     class GameViewController: UIViewController {  
       let p = SCNVector3Zero
    

-- > Compiles and runs.

  1. Change property type to SCNVector4 instead of SCNVector3.

     class GameViewController: UIViewController {  
       var p = SCNVector4Zero
    

-- > Compiles and runs.

EDIT: This problem is fixed in Xcode 7.0 beta-2 (7A121l), if you are getting "Abort trap: 6" due to using a float 3 vector type (such as SCNVector3). From the release notes:

> • A compiler crash when calling C or Objective-C functions that take > SIMD float3 parameters has been fixed. (21294916)

Solution 16 - Swift

Ok, in my case it was because I had an enum nested in a generic class. Now, the strange thing, is that when I isolated the problem (into the BaseDao2), the compiler told me the right error, but in my real BaseDao implementation (which has more stuff), it throw "trap 6".

Type 'DaoError2' nested in generic type 'BaseDao2' is not allowed

When I had this:

class BaseDao2<T>: InjectRestSession{
	
	enum DaoError2: ErrorType{
		case FAILED_RESPONSE(String)
		case INVALID_RESULT(String)
		case FAIL_TO_LIST, FAIL_TO_GET
	}
	
	func get() -> T?{
		return nil
	}
}

Anyway, in my case, I move the DaoError out of the BaseDao and everything compiled. Anyway, my feeling is that "trap 6" is what something cannot compile and the compiler got confused. Starting from a simple case, and adding back what you think might be causing the problem can be helpul to identify the problem by getting the right compile error. In other word, you have to be gentle with the swift compiler.

Solution 17 - Swift

This is what caused the error for me.

Before:

    for (key,value) in hash{
        count += value.count
    }

After:

    for (_,value) in hash{
        count += value.count
    }

It didn't like it that key was never being used anywhere. I am not sure why it should cause the build to fail though.

Solution 18 - Swift

I managed to get my project to build by setting the optimisation level to 'None' under the 'Swift Compiler - Code Generation' menu in the target (not the project) settings. See the screenshot below...

enter image description here

This shouldn't be a permanent solution because it more than doubles the size of the ipa. It should be possible to switch optimisation back on when Xcode 7 comes out of beta.

Solution 19 - Swift

In my case i had @objc protocol with optional methods and when i called its methods also in swift class i got that error, after removing the optional keyword from functions in the protocol the error was gone.

before (with error):

@objc protocol SomeDelegate:NSObjectProtocol{

    optional func someDelegateMethod()
}

class MySwiftClass{
    func notifyMyDelegate(){
        mydelegate?.someDelegateMethod?() //this line caused the error
    }
}

after:

@objc protocol SomeDelegate:NSObjectProtocol{

    func someDelegateMethod()
}

class MySwiftClass{
    func notifyMyDelegate(){
        mydelegate?.someDelegateMethod()
    }
}

Solution 20 - Swift

for me.. I modified the content of a @objc function like so:

before:

        @objc func didConnectWithSession() {
           context!.stream.disconnectAfterSending()
        }

after:

        @objc func didConnectWithSession() {
           //context!.stream.disconnectAfterSending()
        }

This caused the error. I resolved by removing the entire function.

Solution 21 - Swift

I got this message when using do-try-catch in a Failable initializer:

public init?() {
    do {
        ...
        super.init(superParam: try getParamForSuper())
        ...
    } catch {
        ...
    }
}

The compilation succeeded when moving the try call to it's own local variable:

public init?() {
    do {
        ...
        let superParam = try getParamForSuper()
        super.init(superParam: superParam)
        ...
    } catch {
        ...
    }
}

Solution 22 - Swift

In my case I had a private struct Constants declared in both class A and extension A.

Probably it should be giving an error but it didn't.

Solution 23 - Swift

To me what caused this error was:

I created a file to create extensions on UIView. Inside this file, I created a private protocol named Foo.

Then I made:

extension UIView: Foo

Removing the private from the protocol made the error go away.

I guess this is probably a bug. The compiler should warn us about the issue. The same way it warns us we can't add private conformances to types it should tell us that conformance should be using a "public/internal" protocol.

Solution 24 - Swift

I resolved this problem with these steps:

  1. ran 'pod deintegrate'

  2. Makesure podfile like this: platform :ios, '8.0' use_frameworks!

  3. ran 'pod install'

Solution 25 - Swift

In my case, renames several parameters of init methods which is a protocol fails the compilation. I solve it by do it one by one, compiles again after each change.

Solution 26 - Swift

I was having this same problem and I found the problem was that I had changed the build system to "New Build System" after reading an article on "how to speed up your builds" (This is the article btw here)

So to go back to the standard build system:

  1. To enable the new build system, go to File → Project Settings (or Workspace Settings).
  2. Change Build System to Standard Build System.

enter image description here

Hope it helps someone and don't waste hours trying to find out why this was not working!

Solution 27 - Swift

I didn't try other solutions. I got this problem for this setup:

func speacialAdd(_ num1: Int, to num2: Int){
    func specialMultiply(_ digit1: Int, with digit2: Int = num2){ // SOURCE OF PROBLEM
        print(digit2)
        print(digit1)
    }
    
    specialMultiply(5)
}

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print(speacialAdd(5, to: 6))
    }
}

This line is the source of problem. Defaulting it to a argument seems to not work for a nested function

func specialMultiply(_ digit1: Int, with digit2: Int = num2) // ERROR

Solutions are:

func specialMultiply(_ digit1: Int, with digit2: Int) // OK
func specialMultiply(_ digit1: Int, with digit2: Int = 6) // OK

FWIW I actually first wrote this in playground and got a different error:

> Playground execution failed: > > error: Couldn't lookup symbols:
> __T013__lldb_expr_111speacialAddySi_Si2totF4num2L_Sifau

Solution 28 - Swift

In Xcode 9.3, I have re-installed the specific pod, in which warnings appeared and cleared derived data again n again. It worked for me :)

Solution 29 - Swift

I fixed it by going to Xcode -> Preferences -> Locations -> Set Relative option to Derived Data.

Setting Derived Data

Solution 30 - Swift

For me it was MD5.swift issue

What you have to do is search in your project for file name "MD5.swift" even in the pods

and replace all the content with this file here

https://github.com/onmyway133/SwiftHash/blob/master/Sources/MD5.swift

Solution 31 - Swift

This issue is still present in Xcode 10.2.1. After cleaning the build folder, the error went away.

Solution 32 - Swift

For me below statement cause an error.

let dict = mainDict as [String:String]

Fix the issue by force unwraps

let dict = mainDict as! [String:String]

There is nothing related to the compiler. It is just type casting issue, Apple should give proper description instead of the giving compiler error

Solution 33 - Swift

My case, Swift 5.1, Xcode 10.3 (10G8)

Code was crashing Swift when a nested function was using the argument of an outer function as a default parameter.

e.g.

func foo(duration: TimeInterval) {
	func bar(duration: TimeInterval = duration) {
	}
}

I hope this helps.

Solution 34 - Swift

In my case search for

[String: String]

replace with

[String: Any]

Solution 35 - Swift

In my case the problem with "Abort trap: 6" was caused by setting a value of a @Published property defined in a super class, that inherits from ObservableObject (Swift 5).

Error:

class MySuperClass : ObservableObject {
   @Published var myProperty : Int = 0
}

class MySubClass : MySuperClass {
   func someFunc() {
     myProperty = 1
   }
}

Ok:

class MySuperClass : ObservableObject {
   @Published var myProperty : Int = 0

   func setMyProperty(value: Int) {
      myProperty = value
   }
}

class MySubClass : MySuperClass {
   func someFunc() {
     setMyProperty(value: 1) 
   }
}

Solution 36 - Swift

in Xcode 11 and swift 5: Go to project Build settings -> Swift Compiler - code generation -> Optimization Level -> For both Debug & Release select option "No Optimaiztion[-Onone]

enter image description here

Solution 37 - Swift

My problem was with the line:

return ()

i removed the line and problem fixed!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionswalknerView Question on Stackoverflow
Solution 1 - SwiftVyacheslavBakinkskiyView Answer on Stackoverflow
Solution 2 - SwiftS_iOSView Answer on Stackoverflow
Solution 3 - Swiftj.s.comView Answer on Stackoverflow
Solution 4 - SwiftRupak ShakyaView Answer on Stackoverflow
Solution 5 - SwifthunjulyView Answer on Stackoverflow
Solution 6 - SwiftZhaoView Answer on Stackoverflow
Solution 7 - SwiftBMH500View Answer on Stackoverflow
Solution 8 - SwiftVova KalinichenkoView Answer on Stackoverflow
Solution 9 - SwiftBogdanView Answer on Stackoverflow
Solution 10 - SwiftFullMetalFistView Answer on Stackoverflow
Solution 11 - SwiftReDetectionView Answer on Stackoverflow
Solution 12 - Swiftnikdange_meView Answer on Stackoverflow
Solution 13 - SwiftRohitView Answer on Stackoverflow
Solution 14 - Swiftuser3400012View Answer on Stackoverflow
Solution 15 - SwiftBen StahlView Answer on Stackoverflow
Solution 16 - SwiftJeremy ChoneView Answer on Stackoverflow
Solution 17 - SwiftboidkanView Answer on Stackoverflow
Solution 18 - SwiftPJeremyMaloufView Answer on Stackoverflow
Solution 19 - SwiftOleg ShermanView Answer on Stackoverflow
Solution 20 - SwiftdeLux_247View Answer on Stackoverflow
Solution 21 - SwiftJoakimView Answer on Stackoverflow
Solution 22 - SwiftTung FamView Answer on Stackoverflow
Solution 23 - SwiftNuno GonçalvesView Answer on Stackoverflow
Solution 24 - SwiftQL MView Answer on Stackoverflow
Solution 25 - SwiftBill ChanView Answer on Stackoverflow
Solution 26 - SwiftAndresView Answer on Stackoverflow
Solution 27 - SwiftmfaaniView Answer on Stackoverflow
Solution 28 - SwiftDeepa SuryawanshiView Answer on Stackoverflow
Solution 29 - SwiftjawadView Answer on Stackoverflow
Solution 30 - SwiftAhmed SafadiView Answer on Stackoverflow
Solution 31 - SwiftTamás SengelView Answer on Stackoverflow
Solution 32 - SwiftHitesh SuraniView Answer on Stackoverflow
Solution 33 - SwiftWombleView Answer on Stackoverflow
Solution 34 - SwiftMarosdee UmaView Answer on Stackoverflow
Solution 35 - SwiftJan MatysekView Answer on Stackoverflow
Solution 36 - SwiftBatyrCanView Answer on Stackoverflow
Solution 37 - SwiftMehrdadView Answer on Stackoverflow