Objective-C Category import strange behavior

本小妞迷上赌 提交于 2019-12-06 08:17:05

Categories do not work well with traditional Unix static libraries.

If that's your case, it seems that passing the -ObjC option to the linker resolves the issue.

Apple Technical Q&A QA1490 explains it all.

I suspect that you have forgotten to add the Manager+MyCategory.m to the approrpriate target in Xcode. You do not get a linker error because all the symbols exist and there is no compiler warning because you have included the appropriate header files, but at runtime the implementation of the elementWithTag: method is missing.

Apologies, could not add this as a comment...

Just for testing, you may want to add an extern c function declared in the header and implemented in the .m file. If you call this c function within your test code then this will generate a linker error due to an unresolved identifier.

This can make it easier to investigate the problem as it provides immediate feedback and may generate some additional clues as to why the file is not being included.

Given the time frame, I'll assume you've done this, but just in case... make sure that you've cleaned the target, shut down XCode, and then re-open. I've had the project files become corrupted in memory and act strangely.

Barney

I had this issue when upgrading to Xcode 4.

To fix I had to separate my category definition into a separate .m and a .h - Xcode 3 seemed okay with the implementation and interface being in a .h ... but oh no fussy Xcode 4 is rather anal.

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