Reputation: 2379
I've followed this tutorial for setting up a static library with common classes from 3 projects we are working on.
It's pretty simple, create a new static library project on xcode, add the code there, a change some headers role from project
to public
. The tutorial says I should add my library folder to the header search paths
recursively.
Is this the right way to go?
I mean, on my library project, I have files separated in folders like Global/
, InfoScreen/
, Additions/
. I was trying to setup one LOKit.h
file on the root folder, and inside that file #import everything I need to expose. So on my host project I don't need to add the folder recursively to the header search path, and would just #import "LOKit.h"
.
But I couldn't get this to work, the host project won't build complaining about all the classes I didn't add to LOKit.h
, even though the library project builds.
So, my question is, what is the right way of exposing header files when I setup a Cocoa Touch Static Library project on xCode?
Upvotes: 1
Views: 3267
Reputation: 2379
I ended up setting up a LOKit.h
on the project root folder like this:
#import "Global/LOCommon.h"
#import "Additions/LOAdditions.h"
#import "View/LOCustomView1.h"
#import "View/LOCustomView2.h"
And on my host project I set the header search path variable to my library's root folder, without recursion. Whenever I need to, I just import LOKit.h
.
I also included on this library project common libraries (like JSON, FBConnect and Reachabillity) that were shared across projects. This way I only need to update those libraries in one place, once.
Upvotes: 1
Reputation: 8482
When using static libraries I usually go one of the following two ways:
If I created the library myself and it is somewhat tightly coupled to the project which uses the lib, I usually create a source root for the library in the XCode settings. Then you can add the source root as a variable to the header paths recursively.
On the other hand, if the library is either not by me, or is maintained entirely separately from my project, I usually copy a version of the library plus the relevant headers to the project using it and reference those. This is a bit more cumbersome if you need constant updates, but does not break your application if something in the library changes.
Upvotes: 0