Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to patch a library imported with Cocoapods

Tags:

ios

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?

like image 579
Taum Avatar asked May 29 '13 19:05

Taum


People also ask

What command updates a single library in CocoaPods?

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 ).

How do you install CocoaPods patch?

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.


1 Answers

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.

like image 120
Sam Corder Avatar answered Sep 30 '22 03:09

Sam Corder