“Unknown class< MyClass>在Interface Builder文件中“错误可以用行读取修复”[MyClass class]" [英] How “Unknown class <MyClass> in Interface Builder file” error can be fixed with a line reads "[MyClass class]"?

查看:149
本文介绍了“Unknown class< MyClass>在Interface Builder文件中“错误可以用行读取修复”[MyClass class]"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了以下答案,所以我知道Interface Builder文件中的未知类错误可以使用 -ObjC 链接器解决选项。 (仅供参考,MyClass位于静态库中。)

I read the following answer, so I know that "Unknown class in Interface Builder file" error can be solved using the -ObjC linker option. (FYI, MyClass is in static library.)

https:// stackoverflow .com / a / 6092090/534701

我还发现单行 [MyClass class] App Delegate中的代码可以处理相同的问题,而无需使用 -ObjC 选项。 我的问题是代码如何运作。

I've also found that single line of [MyClass class] code in the App Delegate can handle the same problem without using -ObjC option. My Question is how come the code can work.

根据我上面附上的答案,错误发生是因为我的符号静态库未加载。然后,它意味着 [MyClass类] 使链接器在运行时加载符号? (这没有意义)

According to the answer that I've attached above, the error occurs because symbols in my static libraries are not loaded. Then, it means [MyClass class] makes the Linker to load the symbol at runtime? (which doesn't make sense)

推荐答案

链接器将尝试通过删除未使用的符号来减少最终的二进制大小。从Storyboard实例化的类是使用反射创建的,因此链接器无法知道是否正在使用该类,因此它将从最终二进制文件中删除。

The linker will try to reduce the final binary size by removing unused symbols. The classes instantiated from Storyboard are created using reflection, and thus it's impossible to the linker to know if that class is being used, so it's removed from the final binary.

By将该行添加到您的代码中,您强制链接器在编译时(而不是在运行时)添加该类,从而使Storyboard的反射调用按预期工作。

By adding that line to your code you are forcing the linker to add that class at compilation time (not at runtime), making the reflection call from Storyboard to work as expected.

这篇关于“Unknown class< MyClass>在Interface Builder文件中“错误可以用行读取修复”[MyClass class]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆