iOS framework and Category import
Asked Answered
M

2

8

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...

Miraculous answered 21/6, 2013 at 14:4 Comment(2)
it looks curiously '"<...>"' I think you should remove quotes.Frame
@Frame : you're right. It's just a mistake when I typed the code.Miraculous
M
4

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.

Miraculous answered 21/6, 2013 at 15:29 Comment(0)
S
4

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.

Stanfield answered 21/6, 2013 at 14:34 Comment(3)
Thanks but this is not the matter here and Obj-C flag is enough for the moment. What I want is not to have to use this flag anymore.Miraculous
I don't think you can avoid having to use either of those flags. It's fairly standard practice when including frameworks from 3rd parties.Stanfield
Ok my mistake, I'll post the solution after some tests.Miraculous
M
4

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.

Miraculous answered 21/6, 2013 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.