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?
When you run pod update PODNAME , CocoaPods will try to find an updated version of the pod PODNAME , without taking into account the version listed in Podfile. lock . It will update the pod to the latest version possible (as long as it matches the version restrictions in your Podfile ).
Run the command pod patch create POD_NAME . This will create a patches/POD_NAME. diff file in your repository which you can add and commit to your repository. Add plugin 'cocoapods-patch' to your Podfile — this will add a hook that will apply all patches during a pod install.
I won't claim that this is the best option but it is one option. You can use the post install hook in the Podfile to execute the patch command. I've done it by placing the following at the bottom of my Podfile.
post_install do |installer|
puts 'Patching SVGKit to compile with the ios 7 SDK'
%x(patch Pods/path/to/file.m < localpods/patches/fix.patch)
end
Note that if you have any spaces in your path you'll need to escape the backslash that is escaping the space for the shell. "\ " instead of "\ ". See http://stephenjungels.com/jungels.net/articles/diff-patch-ten-minutes.html for a quick way to generate a patch. Because I was working with 1 simple file I only created a simple diff instead of a unified one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With