IOS Infrastructure and Category Import

I just started creating my own framework, regrouping some useful helpers, utilities, tools, etc. Everything works fine, I just wondered if it is possible to import my categories directly into the file of the main file system of headers.

For example, my framework is called myFramework. I put the class name myFramework.h in the public headers in which I wrote all my import data:

#import "MyCategory+Helper.h" #import "MyOtherCategory+Helper.h" #import "AClass.h" ... 

Then I create my framework and distribute it to my developers.

I expect other developers to simply import to access all of my framework categories. This is normal when I use a subclass instead of using categories, but this is not what I expect.

At that time, I use LoadableCategory.h so that my categories work in my structure and tell my developers that they should use the -ObjC flag in the "Other linker flags" settings and import each category as follows:

 #import <myFramework/MyCategory+Helper.h> #import <myFramework/MyOtherCategory+Helper.h> ... 

It may not be possible, but I wonder why? Did I miss something:)

Thanks! Pebie

PS: Sorry for my English ...

+8
ios objective-c objective-c-category
source share
2 answers

As captain Redmuff said,

I made a mistake. After several attempts, I see that with the -all_load linker flag it works even for importing categories. My mistake was in my main header file: poor import, lack of some things, etc. And finally, do not restart my project after the -all_load flag is -all_load .

Now I'm in myFramework.h :

 #import "MyCategory+Helper.h" #import "MyOtherCategory+Helper.h" #import "AClass.h" ... 

In my project, where I use the framework:

1 / Set "Other linker flag" to -all_load (reload -all_load if necessary)

2 / Just #import <myFramework/myFramework.h> in myProjectApp-Prefix.pch for example

Then I do not need to import all other things into my project. Everything seems OK, despite the need to restart Xcode for the first time after adding my framework.

Thanks CaptainRedmuff, I already tested your solution, but in vain. After additional tests, this is normal!

* EDIT Everything works fine until I move on to one of my classes that use one of my categories. Xcode will indicate that I have an error, since this category does not exist. Same problem when I clear my code: ((

There is no visible interface for ... declares a selector ...

** EDIT If I import <myFrameWork/myFramework> into myProjectApp-Prefix.pch but not in #ifdef __OBJC__ conditional , this is normal.

+4
source share

If you want your categories to be included when linking the framework, you need to specify the -all_load parameter in the Other flags section of the linker of your build settings.

+3
source share

All Articles