Failed to demangle superclass with Cocoapods in Xcode 10.2

孤者浪人 提交于 2019-12-22 03:20:58

问题


After moving to Xcode 10.2, when running my app I get a crash with the error failed to demangle superclass of MyClass from mangled name MySuperClass.

The crash occurs when I try to create an instance of MyClass. I am using CocoaPods 1.6.1 and have not yet upgraded to Swift 5. The class in question is defined inside a Pod, and is a subclass of a class defined a different Pod (listed as a sub dependency of the first Pod).

Adding to the complexity (unsure if it is related) is that the super class takes a generic, and the sub class defines a concrete type and does not take a generic. I.e.

// Inside Pod B:
open class MySuperClass<DataType: Decodable> { ... }

// Inside Pod A:
open class MySubClass: MySuperClass<AConcreteStructConformingToCodable> { ... }

// Inside my project:
let myClass = MySubClass()

I have tried overriding the Pod build settings to build with and without optmisation without any change in behaviour.


回答1:


I have discovered this in the Xcode 10.2 Release Notes, under "Swift Compiler" -> "Known Issues":

Linking against a static Swift library might create a binary with missing type metadata because the object files that define the metadata inside the static archive are mistakenly considered unused. (47598583)

This can manifest as a Swift runtime error with a message such as: “failed to demangle superclass of MyClass from mangled name ‘’”.

Workaround: If you can rebuild the static library, try building it with whole module optimization enabled. Otherwise, add -all_load to the linker flags in the client binary to ensure all object files are linked into it.

And I was able to resolve the issue by adding -all_load to Other Linker Flags of the main Project:

Hope this helps someone else!



来源:https://stackoverflow.com/questions/55584094/failed-to-demangle-superclass-with-cocoapods-in-xcode-10-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!