Command failed due to signal: Abort trap: 6

2020-01-28 04:56发布

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 xcode
30条回答
唯我独甜
2楼-- · 2020-01-28 05:35

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.

查看更多
狗以群分
3楼-- · 2020-01-28 05:35

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()
    }
}
查看更多
ら.Afraid
4楼-- · 2020-01-28 05:37

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.

查看更多
小情绪 Triste *
5楼-- · 2020-01-28 05:38

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

enter image description here

查看更多
兄弟一词,经得起流年.
6楼-- · 2020-01-28 05:41

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.

查看更多
聊天终结者
7楼-- · 2020-01-28 05:41

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

查看更多
登录 后发表回答