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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值