Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS framework and Category import

I have just started to create my own framework regrouping some usefull helper, utils, tools etc. Everything works fine, I just wondered if it was possible to import my categories directly in my main headers framework file.

For exemple, my framework is named myFramework. I put a class name myFramework.h in public headers within I wrote all of my imports :

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

Then I build my framework and distribute it to my team developers.

What I expect is that other developers just have to import to access of all of my framework's categories. It's ok when I subclass instead of using categories but it isn't what I expect.

For the while, I use LoadableCategory.h to make my categories work in my framework and specify to my developers that they should use -ObjC flag in "Other Linker flags" settings and import each category like this :

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

May be it isn't possible but I wonder why ? I miss something :)

Thank you ! Pebie

PS : Sorry for my english...

like image 739
Pebie Avatar asked Jun 21 '13 14:06

Pebie


2 Answers

If you want to make sure your categories are included when you link your framework, you need to specify the -all_load parameter in the Other Linker Flags section of your Build Settings.

like image 57
Zack Brown Avatar answered Oct 19 '22 06:10

Zack Brown


As CaptainRedmuff said,

I've done a mistake. After few try, I see that with -all_load linker flag it works even for categories import. My mistake was in my main header file : bad imports, missing some stuff etc. And finally not reload my project after set -all_load flag.

Now I've in myFramework.h:

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

In my project where I use the framework :

1/ Setup "Other Linker Flag" to -all_load (reload XCode if necessary)

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

Then I don't have to import all of the other stuff in my project. Everything seems to be OK despite needed of restart XCode at the very first time after adding my framework.

Thank's CaptainRedmuff, I had already test your solution but in vain. After more tests it's OK !

*EDIT Everything works fine until I go to one of my class who use one of my category. XCode specify me that's I've an error like the category didn't exists. Same issue when I clean my code :((

No visible interface for...declares the selector...

**EDIT If I import <myFrameWork/myFramework> in myProjectApp-Prefix.pch but not within the #ifdef __OBJC__ conditional, it is OK.

like image 30
Pebie Avatar answered Oct 19 '22 06:10

Pebie