iOS开发心得一则

问题描述:在升级XCode4.3.2后,由于new iPad授权导致的一系列混乱后,突然发现原来正常的程序一直报错,问题一直出现在DTCoreText库对UIView扩展的category类中。XCode运行到此处中止,报“Thread1 program received signalSIGABRT”信息提示。

解决经过:经过不停的调试,不停的google,不停的纠结后无果。后来突然想起是否之前解决new iPad真机调试时将编译参数改动导致,随后查询资料,在XCode的“building settings"中的"Other Linker Flag"处指定”-ObjC"参数后重新编译运行后问题解决。

问题原因: 对DTCoreText以static library静态库的方式进行引用,-ObjC参数允许编译器链接包含category的DTCoreText静态库。

参考信息

见Apple Document

A: Why do I get a runtime exception of "selector not recognized" when linking against an Objective-C static library that contains categories?

The "selector not recognized" runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.

To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes. Follow these steps to pass -ObjC to the linker


“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
评论

打赏作者

81886588

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值