Posted By

BenClayton on 03/10/11


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


iPhone: Make categories defined inside libraries actually work

 / Published in: Objective C

There seems to be an bugrelated to static libraries with an implementation file that contains ONLY implementations of category methods. The FIXCATEGORYBUG macro basically just expands to define an interface and implementation of that interface with no methods, just to force something into the .m file that isn't a category.

  1. //CategoryBugHack.h
  2. #define FIX_CATEGORY_BUG(name) @interface FIX_CATEGORY_BUG##name @end @implementation FIX_CATEGORY_BUG##name @end
  3. Then the category .h/.m ...
  5. //NSStringCategory.h
  6. @interface NSString (MyAdditions)
  7. // etc, etc
  8. @end
  10. //NSStringCategory.m
  11. #import "CategoryBugHack.h"
  12. FIX_CATEGORY_BUG(NSString_MyAdditions)
  13. @implementation NSString (MyAdditions)
  14. // etc, etc
  15. @end

Report this snippet  

You need to login to post a comment.