swalkner
swalkner

Reputation: 17379

Command failed due to signal: Abort trap: 6

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

Upvotes: 58

Views: 45829

Answers (30)

S_iOS
S_iOS

Reputation: 239

This is normally a Swift compiler bug, and if compiler is already latest-version, we can only workaround it, for example:

Possible workarounds

#1

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

settings

Above forces compiler to operate a little differently, which seems to prevent crash.

Note that both "-O" and "-Osize" may fix the crash, but I prefer -O to match release's settings, and avoid surprises in release.

#2

Go to "Build settings", and set "Compilation mode" to "Whole Module" instead of "Incremental".

By default for Debug it's Incremental, and for Release it's Whole Module.

#3

Try latest Swift compiler, which is named "toolchain" and is downloadable at:
https://swift.org/download

WARNING: You can not upload such "toolchain" build to App-store .

But at least you should be able to test locally.

For App-store, you need to compile with Swift compiler that comes with your Xcode (or latest Xcode, if your current Xcode version does not compile).

#4

Last and least (don't do this);
edit entire project's and/or pods' source-codes, and ensure guards have separate name than what they guard.
For example, replace:

guard let myVariableName = myVariableName else { return }

With something like:

guard let myDifferentName = myVariableName else { return }

Of course, now all lines after guard need to use myDifferentName.

Upvotes: 23

Rohit
Rohit

Reputation: 1174

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))
    }
}

Upvotes: 1

Rupak Shakya
Rupak Shakya

Reputation: 99

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]'.

Upvotes: 4

nikdange_me
nikdange_me

Reputation: 3017

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

Upvotes: 1

Mehrdad
Mehrdad

Reputation: 1208

My problem was with the line:

return ()

i removed the line and problem fixed!

Upvotes: -1

Oranutachi
Oranutachi

Reputation: 1279

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.

Upvotes: 65

BatyrCan
BatyrCan

Reputation: 6983

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

Upvotes: 0

Jan Matysek
Jan Matysek

Reputation: 1

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) 
   }
}

Upvotes: 0

Marosdee Uma
Marosdee Uma

Reputation: 778

In my case search for

[String: String]

replace with

[String: Any]

Upvotes: 0

Womble
Womble

Reputation: 5289

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.

Upvotes: 0

Hitesh Surani
Hitesh Surani

Reputation: 13577

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

Upvotes: 0

ReDetection
ReDetection

Reputation: 3196

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.

Upvotes: 1

user3151675
user3151675

Reputation: 58149

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

Upvotes: 0

Ahmed Safadi
Ahmed Safadi

Reputation: 4600

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

Upvotes: 0

jawad
jawad

Reputation: 825

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

Setting Derived Data

Upvotes: 0

FullMetalFist
FullMetalFist

Reputation: 208

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

Upvotes: 1

Deepa Suryawanshi
Deepa Suryawanshi

Reputation: 91

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 :)

Upvotes: 0

mfaani
mfaani

Reputation: 36427

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

Upvotes: 0

Bogdan
Bogdan

Reputation: 2617

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.

Upvotes: 1

Andres
Andres

Reputation: 11757

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!

Upvotes: 0

Bill Chan
Bill Chan

Reputation: 3473

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.

Upvotes: 0

QL M
QL M

Reputation: 9

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'

Upvotes: 0

Nuno Gonçalves
Nuno Gonçalves

Reputation: 6815

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.

Upvotes: 0

Tung Fam
Tung Fam

Reputation: 8167

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.

Upvotes: 0

Vova Kalinichenko
Vova Kalinichenko

Reputation: 149

I received this when did that:

protocol ProtocolA {
    associatedtype BType: ProtocolB
}

protocol ProtocolB {
    associatedtype AType: ProtocolA
}

Upvotes: 1

BMH500
BMH500

Reputation: 11

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.

Upvotes: 1

Joakim
Joakim

Reputation: 3294

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 {
        ...
    }
}

Upvotes: 0

Zhao
Zhao

Reputation: 924

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

Upvotes: 1

deLux_247
deLux_247

Reputation: 161

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.

Upvotes: 0

Oleg Sherman
Oleg Sherman

Reputation: 2802

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()
    }
}

Upvotes: 0

Related Questions