Clicky

iOS Dev Nugget 128 Dependency Management for 3rd Party Code: Git Submodules

.

Need to run a code review on your codebase? Hire me

In #126 and #127, I mentioned CocoaPods's a third way, which is to vendor the code directly using Git Submodules (or a similar feature in other version control systems). Like Carthage, it is less intrusive and requires more work than using Cocoapods, but most third party code should work with this approach, and there are a few other benefits:

  • you can easily step into and debug the 3rd party code you are vendoring.
  • you can apply your own fixes – hopefully before submitting them upstream to the maintainer.
  • you can use the latest upstream version even if it hasn't been released as a (Cocoa)pod.
  • depending on how the 3rd party code is structured, you may be able to pick and choose the parts that you need.

Here's how to use it, assuming your project is already managed by Git:

  1. Create a vendor/ directory.

    mkdir vendor

  2. Add the 3rd party code as a submodule:

    git submodule add https://github.com/AFNetworking/AFNetworking.git vendor/AFNetworking

  3. Drag the folders/files that you need into your Xcode project.

  4. Commit your changes to your Xcode project as well as the submodule.

  5. Make changes to the submodule or run git pull origin master to get upstream updates.

You then iterate through steps 2-5 during development.

An important note to working with 3rd party code is not to drop it directly into your Git repository and checking them in. This will make it hard to keep up with changes from upstream.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues