How to patch a library imported with Cocoapods

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'

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.

Tags:

Ios

Cocoapods