开发者

When does a Category come into effect

开发者 https://www.devze.com 2023-04-09 10:48 出处:网络
I\'m a little confused by something regarding Categories. If I have written a Category for开发者_如何学JAVA ClassA called ClassA+Something, at what point does that category come into effect? I\'m assu

I'm a little confused by something regarding Categories. If I have written a Category for开发者_如何学JAVA ClassA called ClassA+Something, at what point does that category come into effect? I'm assuming a single import somewhere will cause the category to be applied to ClassA throughout the project, but where should this import be placed?


If the category's source file is part of the build, it'll come into effect before main() runs, regardless of whether the category's header is imported into other files or not. The only difference made by importing the header is that you'll be able to call the category's methods (in any files that import it) without generating compiler warnings.


I find it easiest to import categories in the precompiled header file (.pch) for my projects.

That way it's available to all my classes with creating compiler warnings.


actually the linker is responsible for adding categories.. if you add -all_load to your linker flags you assure that all categories (+ categories in all sub-libraries) along with all classes are loaded. if you include a header somewhere, the linker will add the category. if you have a complex library tree hierarchy (i had that once with facebook + some other lib depending on SBJson's categories) -all_load is your way to fix crazy runtime errors

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号