Swift compiler segmentation fault after Swift 3 / Xcode 8 port - ios

I have checked multiple answers here in SO, but no solution seems to work for me. When compiling my iOS (≥9.3) app, the following compiler error appears since I converted my project to Swift 3 / Xcode 8.
I tried to clean, delete DerivedData, rebuild Carthage frameworks, etc. - but nothing worked - yet.
Maybe somebody who has experienced this before can immediately spot the problem.
Console output / Stacktrace :
0 swift 0x000000010bc8cb6d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x000000010bc8c5b6 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fffd300dbba _sigtramp + 26
3 libsystem_platform.dylib 000000000000000000 _sigtramp + 754918496
4 swift 0x00000001090c98d2 llvm::Value* llvm::function_ref<llvm::Value* (unsigned int)>::callback_fn<swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*)::$_0>(long, unsigned int) + 530
5 swift 0x00000001091a7600 swift::irgen::emitImpliedWitnessTableRef(swift::irgen::IRGenFunction&, llvm::ArrayRef<swift::irgen::ProtocolEntry>, swift::ProtocolDecl*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 240
6 swift 0x00000001090c96a7 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) + 247
7 swift 0x00000001091a39cd swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*) + 5997
8 swift 0x00000001091a14d7 swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 503
9 swift 0x00000001091138ed swift::irgen::IRGenerator::emitGlobalTopLevel() + 2077
10 swift 0x00000001091d4fcb performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1259
11 swift 0x00000001090a31c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23687
12 swift 0x000000010909b265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
13 swift 0x000000010905882d main + 8685
14 libdyld.dylib 0x00007fffd2e01255 start + 1
15 libdyld.dylib 0x0000000000000067 start + 757067283
And the problematic file / class is the following:
class JSONDataProvider<Input, Output, APIInformation>: DataProvider
where APIInformation: APIAccessInformation, APIInformation.Input == Input,
Output: JSONDataType, Input: Equatable, Input: SignificanceComparable
{
static var updateCallbacksWithoutInputChange: Bool { return false }
// MARK: - Protocol Variables
var callbackId: Int = 0
var callbacks: [Int : (Result<(Output, Input)>) -> ()]
var inputCache: Input?
var outputCache: Result<(Output, Input)>?
// MARK: - Private Properties
fileprivate let apiInformation: APIInformation
fileprivate let requestHandler: URLRequestHandler
// MARK: - Init
init(apiInformation: APIInformation, requestHandler: URLRequestHandler)
{
self.apiInformation = apiInformation
self.requestHandler = requestHandler
self.callbacks = [:]
}
}
For context: (leaving out extensions)
protocol DataProvider
{
associatedtype Input: Equatable, SignificanceComparable
associatedtype Output
static var updateCallbacksWithoutInputChange: Bool { get }
var inputCache: Input? { get set }
var outputCache: Result<(Output, Input)>? { get set }
var callbackId: Int { get set }
var callbacks: [Int : (Result<(Output, Input)>) -> Void] { get set }
func fetchData(from input: Input)
mutating func registerCallback(_ callback: #escaping (Result<(Output, Input)>) -> Void) -> Int
mutating func unregisterCallback(with id: Int)
}
And:
protocol APIAccessInformation
{
associatedtype Input: Equatable, SignificanceComparable
var requestMethod: Alamofire.HTTPMethod { get }
var baseURL: String { get }
func apiParameters(for input: Input) -> [String : Any]
}
Any ideas? Thank you!

Turns out the generic type was the problem. As nobody seems to know exactly why, I have adapted my architecture so I don't need this generic type.
I'm leaving this question here in case others run into a similar issue or someone who knows the exact reason and fix finds this thread.

Related

Crash (SIGABRT) when writing data to UserDefaults after Sheet disappears

I got three similar crash reports that I can't reproduce (all on iOS 14.4). The stracktrace says the following (I only pasted the part where my app is starting):
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001c077d414 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001de2d8b50 pthread_kill + 272 (pthread.c:1392)
2 libsystem_c.dylib 0x000000019bc5bb74 abort + 104 (abort.c:110)
3 libswiftCore.dylib 0x0000000196795f20 swift::fatalError(unsigned int, char const*, ...) + 60 (Errors.cpp:393)
4 libswiftCore.dylib 0x0000000196796078 swift::swift_abortRetainUnowned(void const*) + 36 (Errors.cpp:460)
5 libswiftCore.dylib 0x00000001967e5844 swift_unknownObjectUnownedLoadStrong + 76 (SwiftObject.mm:895)
6 SwiftUI 0x00000001992b0cdc ViewGraph.graphDelegate.getter + 16 (ViewGraph.swift:234)
7 SwiftUI 0x00000001997e4d58 closure #1 in GraphHost.init(data:) + 80
8 SwiftUI 0x00000001997e6550 partial apply for closure #1 in GraphHost.init(data:) + 40 (<compiler-generated>:0)
9 AttributeGraph 0x00000001bbcc9b88 AG::Graph::Context::call_update() + 76 (ag-closure.h:108)
10 AttributeGraph 0x00000001bbcca1a0 AG::Graph::call_update() + 56 (ag-graph.cc:176)
11 AttributeGraph 0x00000001bbccfd70 AG::Subgraph::update(unsigned int) + 92 (ag-graph.h:709)
12 SwiftUI 0x00000001997e1cdc GraphHost.runTransaction() + 172 (GraphHost.swift:491)
13 SwiftUI 0x00000001997e4e1c GraphHost.runTransaction(_:) + 92 (GraphHost.swift:471)
14 SwiftUI 0x00000001997e37a8 GraphHost.flushTransactions() + 176 (GraphHost.swift:459)
15 SwiftUI 0x00000001997e2c78 specialized GraphHost.asyncTransaction<A>(_:mutation:style:) + 252 (<compiler-generated>:0)
16 SwiftUI 0x00000001993bd2fc AttributeInvalidatingSubscriber.invalidateAttribute() + 236 (AttributeInvalidatingSubscriber.swift:89)
17 SwiftUI 0x00000001993bd1f8 AttributeInvalidatingSubscriber.receive(_:) + 100 (AttributeInvalidatingSubscriber.swift:53)
18 SwiftUI 0x00000001993bd914 protocol witness for Subscriber.receive(_:) in conformance AttributeInvalidatingSubscriber<A> + 24 (<compiler-generated>:0)
19 SwiftUI 0x000000019956ba34 SubscriptionLifetime.Connection.receive(_:) + 100 (SubscriptionLifetime.swift:195)
20 Combine 0x00000001a6e67900 ObservableObjectPublisher.Inner.send() + 136 (ObservableObject.swift:115)
21 Combine 0x00000001a6e670a8 ObservableObjectPublisher.send() + 632 (ObservableObject.swift:153)
22 Combine 0x00000001a6e4ffdc PublishedSubject.send(_:) + 136 (PublishedSubject.swift:82)
23 Combine 0x00000001a6e76994 specialized static Published.subscript.setter + 388 (Published.swift:0)
24 Combine 0x00000001a6e75f74 static Published.subscript.setter + 40 (<compiler-generated>:0)
25 MyApp 0x00000001005d1228 counter.set + 32 (Preferences.swift:0)
26 MyApp 0x00000001005d1228 Preferences.counter.modify + 120 (Preferences.swift:0)
27 MyApp 0x00000001005ca440 MyView.changeCounter(decrease:) + 344 (MyView.swift:367)
28 MyApp 0x00000001005cf110 0x100584000 + 307472
29 MyApp 0x00000001005e65d8 thunk for #escaping #callee_guaranteed () -> () + 20 (<compiler-generated>:0)
30 MyApp 0x00000001005a8828 closure #2 in MySheet.body.getter + 140 (MySheet.swift:0)
What is happening is, that I have a Sheet with a button and when clicking on it the sheet disappears and in the onDisappear the changeCounter method in the main View MyView is called to change the counter. The method changeCounter is passed to the Sheet from MyView when calling/opening the Sheet.
This is the .sheet method in MyView:
.sheet(item: $activeSheet) { item in
switch item {
case .MY_SHEET:
MySheet(changeCounter: {changeCounter(decrease: true)}, changeTimer, item: $activeSheet)
}
}
This is the (important part of the) sheet:
struct MySheet: View {
var changeCounter: () -> Void
var changeTimer: () -> Void
#Binding var item: ActiveSheet?
#State var dismissAction: (() -> Void)?
var body: some View {
GeometryReader { metrics in
VStack {
Button(action: {
self.dismissAction = changeCounter
self.item = nil
}, label: {
Text("change_counter")
})
Button(action: {
self.dismissAction = changeTimer
self.item = nil
}, label: {
Text("change_timer")
})
}.frame(width: metrics.size.width, height: metrics.size.height * 0.85)
}.onDisappear(perform: {
if self.dismissAction != nil {
self.dismissAction!()
}
})
}
}
Here is changeCounter with the preferences object:
struct MyView: View {
#EnvironmentObject var preferences: Preferences
var body: some View {...}
func changeCounter(decrease: Bool) {
if decrease {
preferences.counter -= COUNTER_INTERVAL
}
}
}
The Preferences is an ObservableObject with the counter variable:
class Preferences: ObservableObject {
let userDefaults: UserDefaults
init(_ userDefaults: UserDefaults) {
self.userDefaults = userDefaults
self.counter = 0
}
#Published var counter: Int {
didSet {
self.userDefaults.set(counter, forKey: "counter")
}
}
}
It changes a value in the userDefaults that are UserDefaults.standard.
Anyone has an idea how that crash can happen and in what situations? Because it only happened three times now on users devices and I can't reproduce it.
Let's analyze
Button(action: {
self.dismissAction = changeCounter 1)
self.item = nil 2)
}, label: {
Line 1) changes internal sheet state initiating update of sheet's view
Line 2) changes external state initiating close of sheet (and probably update of parent view).
It even sounds as two conflicting process (even if there are no dependent flows, but looking at your code second depends on result of first). So, this is very dangerous logic and should be avoided.
In general, as I wrote in comment, changing two states in one closure is always risky, so I would rewrite logic to have something like (sketch):
Button(action: {
self.result = changeCounter // one external binding !!
}, label: {
, ie. the one state change that initiates some external activity...
Possible workaround for your code (if for any reason you cannot change logic) is to separate changes of those states in time, like
Button(action: {
self.dismissAction = changeCounter // updates sheet
DispatchQueue.main.async { // or after some min delay
self.item = nil // closes sheet after (!) update
}
}, label: {

Realm: How to fix 'Invalid property name' RLMException during migration

My iOS app uses RealmSwift, and it is crashing during migration from an older version of the app. The error is: RLMException: Invalid Property Name <name> for class <class>.
The crash seems to be happening because of the following sequence of migrations:
Initial: Created a model (lets call it Story)
class Story: Object, Mappable {
#objc dynamic var _id = ""
#objc dynamic var lastModified: Date?
#objc dynamic var name = ""
#objc dynamic var content = ""
override static func primaryKey() -> String? {
return ServerKey.id
}
override static func indexedProperties() -> [String] {
return ["name"]
}
}
Migration X: Created another model using migration.create (lets call it Book) which contains the model created in the previous step (Book contains Story)
private class func migrateToVersionX(_ migration: Migration) {
migration.enumerateObjects( <perform unrelated migration to change some values on story objects> )
migration.create("Book", value: ["stories": <array containing stories>])
}
Migration X+2: Added a new field to Story (Story.author)
class Story: Object, Mappable {
#objc dynamic var _id = ""
#objc dynamic var lastModified: Date?
#objc dynamic var name = ""
#objc dynamic var content = ""
#objc dynamic var author = ""
override static func primaryKey() -> String? {
return ServerKey.id
}
override static func indexedProperties() -> [String] {
return ["name", "author"]
}
}
When a user has a version older than MigrationX, the app crashes with the following error (modified for this example)
'RLMException', reason: 'Invalid property name 'author' for class 'Story'.'
The app crashes at the migration.create call. This is the stack trace
Fatal Exception: RLMException
Invalid property name 'author' for class 'Story'.
0 CoreFoundation
__exceptionPreprocess
1 libobjc.A.dylib
objc_exception_throw
2 Realm
RLMAccessor.mm line 567
RLMDynamicGetByName
3 RealmSwift
Object.swift line 362
DynamicObject.subscript.getter
4 RealmSwift
<compiler-generated> line 0
#objc DynamicObject.value(forUndefinedKey:)
5 Foundation
-[NSObject(NSKeyValueCoding) valueForKey:]
6 Realm
RLMObjectBase.mm line 174
-[RLMObjectBase valueForKey:]
7 Realm
RLMObjectBase.mm line 451
RLMValidatedValueForProperty
8 Realm
RLMAccessor.mm line 633
RLMAccessorContext::propertyValue(objc_object*, unsigned long, RLMProperty*)
9 Realm
RLMAccessor.mm line 776
RLMAccessorContext::value_for_property(objc_object*,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> > const&, unsigned long)
10 Realm
object_accessor.hpp line 267
realm::Object realm::Object::create<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, std::__1::shared_ptr<realm::Realm> const&, realm::ObjectSchema const&, objc_object* __strong, bool, realm::BasicRow<realm::Table>*)
11 Realm
row.hpp line 759
RLMCreateObjectInRealmWithValue
12 Realm
RLMAccessor.mm line 752
realm::BasicRowExpr<realm::Table> RLMAccessorContext::unbox<realm::BasicRowExpr<realm::Table> >(objc_object*, bool, bool)
13 Realm
list.hpp line 192
auto realm::List::dispatch<void realm::List::add<objc_object* __strong&, RLMAccessorContext>(RLMAccessorContext&, objc_object* __strong&&&, bool)::'lambda'(objc_object* __strong&)>(objc_object* __strong&&&) const
14 Realm
RLMAccessor.hpp line 77
void RLMAccessorContext::enumerate_list<void realm::List::assign<objc_object* __strong&, RLMAccessorContext>(RLMAccessorContext&, objc_object* __strong&&&, bool)::'lambda'(objc_object* __strong&&&)>(objc_object*, objc_object* __strong&&&)
15 Realm
list.hpp line 220
void realm::List::assign<objc_object* __strong&, RLMAccessorContext> (RLMAccessorContext&, objc_object* __strong&&&, bool)
16 Realm
object_accessor.hpp line 94
void realm::Object::set_property_value_impl<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, realm::Property const&, objc_object* __strong, bool, bool)
17 Realm
object_accessor.hpp line 281
realm::Object realm::Object::create<objc_object* __strong, RLMAccessorContext>(RLMAccessorContext&, std::__1::shared_ptr<realm::Realm> const&, realm::ObjectSchema const&, objc_object* __strong, bool, realm::BasicRow<realm::Table>*)
18 Realm
row.hpp line 759
RLMCreateObjectInRealmWithValue
19 Realm
RLMRealm.mm line 840
-[RLMRealm createObject:withValue:]
20 Realm
RLMMigration.mm line 135
-[RLMMigration createObject:withValue:]
21 RealmSwift
Migration.swift line 129
Migration.create(_:value:)
22 Project Name
MigrationHelper.swift line 187
specialized static MigrationHelper.migrateToVersionX(_:)
I think what is happening is that the migration.create function in MigrationX is looking at the Story class and finding the author field, even though it formally isn't introduced until MigrationX+2.
Any thoughts on why this crash is happening and how to appropriately handle this scenario would be greatly appreciated.

Workaround for specific generic type parameter

The situation:
I have two protocols, one with a static method:
protocol DataSourceable {
static func getMoreData<T: DataAccepting>(someObject: T)
}
protocol DataAccepting {
func accept(data: [Any])
}
extension DataAccepting where Self: UIViewController { }
which compiles fine.
Once I define a class with a type parameter conforming to DataSourceable:
class SampleViewController<T: DataSourceable>: UIViewController {...}
I get a Segmentation Fault: 11 and the compiler crashes.
0 swift 0x0000000112445b6d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x00000001124455b6 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fffa4bd9bba _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000000002 _sigtramp + 1531077730
4 swift 0x000000010f8bd5bd swift::irgen::emitCategoryData(swift::irgen::IRGenModule&, swift::ExtensionDecl*) + 2285
5 swift 0x000000010f8c2425 swift::irgen::IRGenModule::emitGlobalDecl(swift::Decl*) + 1189
6 swift 0x000000010f8c1e85 swift::irgen::IRGenModule::emitSourceFile(swift::SourceFile&, unsigned int) + 133
7 swift 0x000000010f98dfe2 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1282
8 swift 0x000000010f85c1c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23687
9 swift 0x000000010f854265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
10 swift 0x000000010f81182d main + 8685
11 libdyld.dylib 0x00007fffa49cd255 start + 1
12 libdyld.dylib 0x00000000000000c6 start + 1533226610
**More_Stuff**...
While emitting IR for source file /xx/xx/xx/xx/xx/xx/xx/SampleViewController.swift
The end goal is to be able to do this:
class SampleViewController<T: DataSourceable>: UIViewController, DataAccepting {
var intArray = [Int]()
func setup() {
T.getMoreData(dataAcceptor: self)
}
func accept(data: [Any]) {
intArray = data
}
}
struct SampleModel: DataSourceable {
static func getMoreData<T: DataAccepting>(dataAcceptor: T) {
var anIntArray = [Int]()
someObject.accept(anIntArray)
}
}
And then make a SampleViewController<SampleModel>.
This will allow me to let the SampleModel deal with sourcing data for the controller. The SampleModel decides how to get the data, then using the accept() function on the controller it can give the data to the SampleController.
This seems to be a compiler bug. However, you should avoid this design in general, as we discussed in chat.

Swift compiler segmentation fault with generic recursive function

I've run into an interesting issue with the Swift compiler, which seems to be caused by a very simple generic function. I've got a workaround, but I'd really like to understand what the underlying issue is.
In my app I have a requirement to fade in some UICollectionViewCells in a given order, sequentially, with a slight overlap between the animations.
I've implemented this using the methods below. The revealCells method takes an array of cells. If the collection is empty, it simply returns. Otherwise it animates the fade-in on the first cell in the array, and then waits a certain amount of time before making a recursive call to itself, passing all the cells except the one it just animated.
Code below:
func revealCells(cells:[UICollectionViewCell],animationTime:NSTimeInterval,overlap:Double) {
if cells.count > 0 {
let firstCell = cells.first
UIView.animateWithDuration(0.3, animations: { () -> Void in
firstCell?.alpha = 1.0
let timeMinusOverlap = animationTime - overlap
let delayTime = dispatch_time(DISPATCH_TIME_NOW,Int64(timeMinusOverlap * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue(), { () -> Void in
self.revealCells(self.cdr(cells),animationTime: animationTime,overlap: overlap)
})
})
}
}
}
//Returns the collection passed into the function with its first element removed
//i.e the traditional LISP cdr function
func cdr<T>(input:[T]) -> [T] {
var rVal = [T]()
if input.count == 1 {
rVal.append(input.first!)
} else {
rVal = [T](input[1...input.count-1])
}
return rVal
}
All this works fine in the simulator. But when I try to archive the build, the swift compiler crashes with the message Swift Compiler Error Command failed due to signal: Segmentation fault 11. My setup is Xcode 6.3.1 (iOSSDK 8.3), and my min deployment target is 8.3.
Fixing the problem is trivial - if I just replace the code inside the dispatch_after with:
let newCells = [UICollectionViewCell](cells[1...cells.count-1])
self.revealCells(newCells,animationTime: animationTime,overlap: overlap)
the problem goes away. So it seems to be something to do with the generic function, or possibly something block related.
Stack trace is:
0 swift 0x000000010105ba18 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x000000010105bef4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8725ef1a _sigtramp + 26
3 libsystem_platform.dylib 0x000000000000000f _sigtramp + 2027557135
4 swift 0x00000001021a98cb llvm::AsmPrinter::EmitFunctionBody() + 4379
5 swift 0x000000010116c84c llvm::ARMAsmPrinter::runOnMachineFunction(llvm::MachineFunction&) + 220
6 swift 0x0000000100d81d13 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 99
7 swift 0x00000001024d5edf llvm::FPPassManager::runOnFunction(llvm::Function&) + 495
8 swift 0x00000001024d60cb llvm::FPPassManager::runOnModule(llvm::Module&) + 43
9 swift 0x00000001024d658f llvm::legacy::PassManagerImpl::run(llvm::Module&) + 975
10 swift 0x0000000100a09b41 performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 4369
11 swift 0x0000000100a09cb3 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
12 swift 0x0000000100945687 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 6647
13 swift 0x0000000100943ae6 main + 1814
14 libdyld.dylib 0x00007fff8a46b5c9 start + 1
(a long list of program arguments, which are mostly the names of file being compiled)
1. Running pass 'Function Pass Manager' on module '/Users/tolleyr/Library/Developer/Xcode/DerivedData/ParseTestQuiz-fgnfjkxxlyqfnrfrfntgtsjnrcfv/Build/Intermediates/ArchiveIntermediates/ParseTestQuiz/IntermediateBuildFilesPath/ParseTestQuiz.build/Release-iphoneos/ParseTestQuiz.build/Objects-normal/armv7/QuizQuestionViewController.o'.
2. Running pass 'ARM Assembly / Object Emitter' on function '#_TFC13ParseTestQuiz26QuizQuestionViewController13viewDidAppearfS0_FSbT_'
(the last part enabled me to figure out what code was causing the problem). The command being run was CompileSwift normal armv7
I'm going to file a radar for this, since the compiler itself is crashing , but thought I'd post it here in case anyone has an idea of what might be going on, or has run into the same issue.

MKMapViewDelegate Command failed due to signal: Segmentation fault: 11

i have a very weird problem with a MKMapViewDelegate when i implement this method give me an error that i do not understand
The error only disappear when i delete the whole function,
i tried to make a empty function returning nil but give me the same error.
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation.isKindOfClass(MKUserLocation.classForCoder()) {
return nil
}
let AnnotationIdentifier:NSString = "AnnotationIdentifier"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(AnnotationIdentifier)
if annotationView != nil {
return annotationView
}else {
var annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: AnnotationIdentifier)
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "btn_fav.png")
return annotationView
}
}
The error:
Command failed due to signal: Segmentation fault: 11
CompileSwift normal arm64 /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift
cd /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c "/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Classes/NetClass/Downloader.swift" -primary-file "/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift" "/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Widget/ToggleView.swift" .
.
.
.
0 swift 0x00000001019df028 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001019df514 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff9a2dc5aa _sigtramp + 26
3 libsystem_platform.dylib 000000000000000000 _sigtramp + 1708276336
4 swift 0x0000000100fe90ea swift::ClangImporter::Implementation::loadAllMembers(swift::Decl const*, unsigned long long, bool*) + 3130
5 swift 0x0000000101da2834 swift::IterableDeclContext::loadAllMembers() const + 100
6 swift 0x0000000101d995dc swift::NominalTypeDecl::getMembers(bool) const + 28
7 swift 0x0000000101dc029f swift::NominalTypeDecl::lookupDirect(swift::DeclName) + 79
8 swift 0x0000000101dbe96a swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 3146
9 swift 0x0000000100fe5941 (anonymous namespace)::SwiftDeclConverter::VisitObjCPropertyDecl(clang::ObjCPropertyDecl const*, swift::DeclContext*) + 161
10 swift 0x0000000100fe0d0d clang::declvisitor::Base<clang::declvisitor::make_const_ptr, (anonymous namespace)::SwiftDeclConverter, swift::Decl*>::Visit(clang::Decl const*) + 3117
11 swift 0x0000000100fe005b swift::ClangImporter::Implementation::importDeclImpl(clang::NamedDecl const*, bool&, bool&) + 331
12 swift 0x0000000100fe4912 swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, bool) + 226
13 swift 0x0000000100fe879e swift::ClangImporter::Implementation::loadAllMembers(swift::Decl const*, unsigned long long, bool*) + 750
14 swift 0x0000000101da2834 swift::IterableDeclContext::loadAllMembers() const + 100
15 swift 0x0000000101d99a95 swift::ExtensionDecl::getMembers(bool) const + 21
16 swift 0x0000000101dc027d swift::NominalTypeDecl::lookupDirect(swift::DeclName) + 45
17 swift 0x0000000101dbe96a swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 3146
18 swift 0x0000000101cc6288 swift::TypeChecker::lookupMember(swift::Type, swift::DeclName, swift::DeclContext*, bool) + 200
19 swift 0x0000000101c34e2c swift::constraints::ConstraintSystem::lookupMember(swift::Type, swift::DeclName) + 220
20 swift 0x0000000101c6b32d swift::constraints::ConstraintSystem::simplifyMemberConstraint(swift::constraints::Constraint const&) + 2173
21 swift 0x0000000101c6dc88 swift::constraints::ConstraintSystem::simplifyConstraint(swift::constraints::Constraint const&) + 216
22 swift 0x0000000101c354bc swift::constraints::ConstraintSystem::addConstraint(swift::constraints::Constraint*, bool, bool) + 28
23 swift 0x0000000101c5a8a5 swift::ASTVisitor<(anonymous namespace)::ConstraintGenerator, swift::Type, void, void, void, void, void>::visit(swift::Expr*) + 9317
24 swift 0x0000000101c5c502 (anonymous namespace)::ConstraintWalker::walkToExprPost(swift::Expr*) + 162
25 swift 0x0000000101d6627f (anonymous namespace)::Traversal::visit(swift::Expr*) + 6431
26 swift 0x0000000101d62765 swift::Expr::walk(swift::ASTWalker&) + 53
27 swift 0x0000000101c583b0 swift::constraints::ConstraintSystem::generateConstraints(swift::Expr*) + 96
28 swift 0x0000000101c90ab6 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::Type, swift::Type, bool, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*) + 518
29 swift 0x0000000101cd73e3 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 291
30 swift 0x0000000101cd64c3 swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, swift::SourceLoc) + 371
31 swift 0x0000000101cd6b8f swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 95
32 swift 0x0000000101c86b65 typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 421
33 swift 0x0000000101c87476 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, unsigned int) + 1734
34 swift 0x0000000100fc07dd swift::CompilerInstance::performSema() + 2253
35 swift 0x0000000100d54831 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 1953
36 swift 0x0000000100d5294d main + 1677
37 libdyld.dylib 0x00007fff960e05fd start + 1
38 libdyld.dylib 0x0000000000000061 start + 1777465957
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Classes/NetClass/Downloader.swift -primary-file /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Widget/ToggleView.swift /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Classes/Entities/Mapa.swift /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Classes/Entities/Edificio__c.swift .
.
.
.
.
1. While type-checking 'loadMapa' at /Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift:56:5
2. While type-checking expression at [/Users/Fortis/Proyectos/IOS Apps/Abilia/Abilia iOS/Abilia/Abilia/Vistas/Proyecto/MapaViewController.swift:57:9 - line:57:29] RangeText="mapaView.delegate = s"
func loadMapa () {
mapaView.delegate = self
var theCoord = CLLocationCoordinate2DMake(0, 0)
if let coordenadasU = coordenadas {
let coordArray:[NSString] = coordenadasU.componentsSeparatedByString(",") as [NSString]
if coordArray.count > 1 {
let lat: CLLocationDegrees = coordArray[0].doubleValue;
let long: CLLocationDegrees = coordArray[1].doubleValue;
theCoord = CLLocationCoordinate2DMake(lat, long)
}
}
pointAnnotation.coordinate = theCoord;
mapaView.addAnnotation(pointAnnotation)
let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)
let region:MKCoordinateRegion = MKCoordinateRegion(center: theCoord, span: span)
mapaView.setRegion(region, animated: true)
mapaLoaded = true;
}
This is one of Swift's many bugs where the compiler suddenly crashes because of specific code in your app it cannot handle.
You have to isolate the problematic part (e.g. by commenting out parts of the screen) and once it compiles again find a workaround to use different code.
How does your method loadMapa look like? It's the cause the compiler mentioned.
I had same error when subclassing UIButton and overriding selected property like this:
class ActionButton: UIButton {
override var selected: Bool = true {
didSet {
updateBackgroundColor()
}
}
}
Solution was to remove ' = true' from the override statement:
class ActionButton: UIButton {
override var selected: Bool {
didSet {
updateBackgroundColor()
}
}
}
I'm just guessing but I would double-check if you implemented your delegate method exactly right way... With all exclamation marks correctly given... '!' at the end of MKAnnotationView! seems to be a bit suspicious.
I've searched why The error: "Command failed due to signal: Segmentation fault: 11" is causing problems in my app... My app is Parse dependent. I found out that Parse made changes to method:
query.findObjectsInBackgroundWithBlock({ (objects : [AnyObject]?, error : NSError?) -> Void in
to
query.findObjectsInBackgroundWithBlock({ (objects : [**PFObject**]?, error : NSError?) -> Void in
I've changed it all, and now it works. Hope this will help someone using Parse. Cheers
Not really a specific answer, but I wanted to add another possible cause of this bug (since it's still quite common).
My program had code like so:
if (myArray.count > 0) && (.Foo != myArray.last) {
// Do something
}
In my case .Foo belonged to an enum for which I'd implemented Equatable, however, for some reason the Swift compiler didn't highlight my comparison to myArray.last as an error (non-optional compared to optional) and produced a segmentation fault.
In my case the fix was simply to use myArray.last! since the myArray.count > 0 ensures this will always succeed (must be at least one element).
As usual, once you know what the bug is, be sure to pass it on to bug report.apple.com!

Resources