问题
Can't archive
My app runs fine (Xcode 6.3.2, swift based) on Simulator and on multiple devices. But when I try to archive it I get the error Command failed due to signal: Segmentation fault: 11
.
Others face same problem
Segmentation Fault 11 when running Swift app
"Command failed due to signal: Segmentation fault: 11" - What is the issue?
Command failed due to signal: Segmentation fault: 11
Root cause?
But it seems that each have different reasons for getting the error.. I am unable to comprehend the error message I am getting. Posted below, any hints or tips would be greatly appreciated!
Error log
0 swift 0x0000000108e5d2b8 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x0000000108e5d794 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8897bf1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff574b7b28 _sigtramp + 3467885608
4 swift 0x0000000108a053f2 swift::serialization::Serializer::writeCrossReference(swift::Decl const*) + 578
5 swift 0x0000000108a0e275 swift::serialization::Serializer::writeAllDeclsAndTypes() + 2181
6 swift 0x0000000108a0f2f8 swift::serialization::Serializer::writeAST(llvm::PointerUnion<swift::Module*, swift::SourceFile*>) + 2600
7 swift 0x0000000108a11960 swift::serialization::Serializer::writeToStream(llvm::raw_ostream&, llvm::PointerUnion<swift::Module*, swift::SourceFile*>, swift::SILModule const*, swift::SerializationOptions const&) + 144
8 swift 0x0000000108a12521 swift::serialize(llvm::PointerUnion<swift::Module*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*) + 321
9 swift 0x0000000108746c1a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 5514
10 swift 0x00000001087454e6 main + 1814
11 libdyld.dylib 0x00007fff8db235c9 start + 1
12 libdyld.dylib 0x0000000000000080 start + 1917700792
回答1:
Solved it. Problem was two things: 1) Converting to Double 2) Handling an empty array
Converting to Double
Changed from var lat: Double? = d["lat"].doubleValue
to var lat: Double? = Double(d["lat"].doubleValue)
Handling an empty array
Changed from
let brands = d["brands_unfiltered"].arrayValue {
if brands == [] {
// Do nothing (empty)
}
else{
// Do stuff
}
To
if let brands = d["brands_unfiltered"].arrayValue as Array! {
// Do stuff
}
To find the root cause I deactivated larges part of the code until I found what got the archiving not to function. Thereafter the solution was pretty straight forward. Hope this helps someone else struggling with the same error.
回答2:
I found the code that cause my "Archive" action to fail with this error "Command failed due to signal: Segmentation fault: 11"
When I use the indexPath in the cellForRowAtIndexPath function, I need to put an exclamation mark (i.e indexPath! instead of indexPath). However, I still puzzled by why there is such error if I omit the exclamation mark. Does anyone know the reason?
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
// code to get cell, etc
let thumbnailImage = self.userPhotos?.getFromCacheOrDownload(username,
circle: team.circle(), delegate: self, indexPath: indexPath!)
cell.userPhotoImageView.image = thumbnailImage
return cell
}
来源:https://stackoverflow.com/questions/31077235/segmentation-fault-11-xcode-6-3