TL;DR
I got "trap 6" error when I tried to build my App. I tried to fix it for a whole day. I fixed it by simply cloning the repo to somewhere else and build it. It might be caused by some cached build file somewhere in the project folder, which is not tracked by version control.
Why I am certain it is caused by some cached file in that project folder
I tried "Clean" action in "Product" menu. I also tried deleting "Derrived Data" folder in "Project" window. None of these helped.
I also tried to checkout my master branch, which I know it should build. But I got the same error which makes no sense.
I created some demo project to mimic the minimal setup of my App. All of them can be built without any error.
I cloned my repo somewhere else and checked out the exact commit which is giving me "trap 6" error. Build, succeeded!
I copied the original "trap 6" folder to somewhere else, I still got the same error.
PS.
Another thing is that, I got this error when I was using Xcode 7 beta. I updated to beta 2 because I see someone said that beta 2 fixed this problem in this forum. After updating to beta 2, I still got this error.
--------
I spent my whole day trying to debuging where the error came from. WASTED... 😟
I hope this post can help others and save someone's time.
EDIT:
I just found out why I was getting "Abort trap 6". Whenever I put one of my struct as a parameter of a `init` and try to access its variables, it happens.
My struct is just a plain Swift struct which conforms to `Decodable` in Argo, the functional JSON decoding framework by thoughtbot.
The whole snippet compiles, until you uncomment that marked line.
import SwiftDailyAPI
class T {
init(newsMeta: NewsMeta) {
print(newsMeta)
// Uncomment the next line, and "Abort trap 6" you will have
// print(newsMeta.newsId)
}
func t(newsMeta: NewsMeta) {
print(newsMeta)
print(newsMeta.newsId)
}
}