Reputation: 17379
Since Xcode 7 and Swift 2.0, I get the error above, like in the screenshot shown here:
I have no idea where this is coming from, cleaning and deleting derived data didn't work.
Anyone else experiencing this problem?
Project settings:
Target settings:
Upvotes: 58
Views: 45829
Reputation: 239
This is normally a Swift compiler bug, and if compiler is already latest-version, we can only workaround it, for example:
Go to project Build settings -> Swift Compiler - code generation -> Optimization Level
-> For both Debug & Release select option "Fast,Single-File Optimization[-O]
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.
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'sWhole Module
.
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).
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 usemyDifferentName
.
Upvotes: 23
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
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
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
Reputation: 1208
My problem was with the line:
return ()
i removed the line and problem fixed!
Upvotes: -1
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
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]
Upvotes: 0
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
Reputation: 778
In my case search for
[String: String]
replace with
[String: Any]
Upvotes: 0
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
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
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
Reputation: 58149
This issue is still present in Xcode 10.2.1. After cleaning the build folder, the error went away.
Upvotes: 0
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
Reputation: 825
I fixed it by going to Xcode -> Preferences -> Locations -> Set Relative
option to Derived Data.
Upvotes: 0
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
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
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
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
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:
Hope it helps someone and don't waste hours trying to find out why this was not working!
Upvotes: 0
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
Reputation: 9
I resolved this problem with these steps:
ran 'pod deintegrate'
Makesure podfile like this: platform :ios, '8.0' use_frameworks!
ran 'pod install'
Upvotes: 0
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
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
Reputation: 149
I received this when did that:
protocol ProtocolA {
associatedtype BType: ProtocolB
}
protocol ProtocolB {
associatedtype AType: ProtocolA
}
Upvotes: 1
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
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
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
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
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