I’m writing a static library that has dependencies on other libraries (in my case SBJSON and ASIHTTPRequest).
If I compile these external dependencies into my library then I can’t link against other libraries that have these classes compiled in. As my goal is to create a set of static libraries for my company that can be imported into any new app, compiling these dependencies into the library is obviously not an option.
Does anyone have any advice / best practices for creating a suite of shared static libraries with common dependencies?
You could use a dependency manager like CocoaPods or VendorKit to pull in the required library, as well as all it’s transitive dependencies – libraries that the library depends on.
It’s the job of the dependency manager to manage any conflicts in transitive dependencies – eg if two libraries both use different versions of SBJSON, it will work out what to do. All you have to do is declare the top level library you want in a config file and it will work out what sub-libraries are needed and pull them into your Xcode Project.
CocoaPods has a nice way of managing this by pulling in the all of the libraries as source, and then compiling them all into a single static library – in a separate project. This is then linked into your project via a workspace.
VendorKit takes a similar approach, but uses a single project file.
Both CocoaPods and VendorKit allow you to easily publish your library to a central repository. CocoaPods allows you to maintain your own private or public fork of the central repo, if you wish – ie as an enterprise repository.
Most of the time this will get you out of trouble. In rare cases your library might depend on a very specific, older version of another common library. In this case you could use a tool to rename all of the header/impl files in that library to avoid collisions.
[Edit]: As of January, 2013 there is also a new contender – Maven Xcode plugin.