Search code examples
ioscocoapods

How to patch a library imported with Cocoapods


My iOS app uses Cocoapods to manage libraries such as AFNetworking, SDWebImage etc.

One of this library happens to have a bug that's been fixed in the bleeding edge version but it has not been propagated to the cocoapods version yet. I'd like to make a patch for this library and be able to share it with my team. What's the recommended way to deal with this?

On a side note: I'd imagine it might come a time where a similar situation could happen where I will want to fork a library. It would be nice if I then had a way to merge my changes into new versions as the library gets updated. Could a similar workflow be used in that case?


Solution

  • Forking the library, applying your patch, and pointing to your fork in the Podfile would be your best option.

    If the library contains the podspec:

    pod '<library', :git => 'https://github.com/yourname/<library>.git'
    

    If the library does not contain the podspec, you have to copy the podspec to a local path and adjust it:

    pod '<library>', :podspec => 'local/path/to/<library>.podspec'