Best practice for static library dependencies

后端 未结 3 733
借酒劲吻你
借酒劲吻你 2021-01-31 09:06

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-31 09:47

    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.

提交回复
热议问题