Hacking on Empty

eat something, you'll feel better

Archive for the ‘workarounds’ Category

Resolving the conflict between AFNetworking and SDWebImage

with one comment

RestKit and SDWebImage are both very useful libraries but they conflict.  The problem is that RestKit depends on AFNetworking, and both AFNetworking and SDWebImage add the same methods to UIImageView.  Fortunately, there is a solution that doesn’t involve forking any repos.  It’s still a hack, but it works.

First, go get the AFNetworking podspec for whatever version you are using and copy it into your repo.  Now edit this podspec and add the following lines:


s.exclude_files = 'AFNetworking/UIImageView+AFNetworking.*'
s.dependency 'AFNetworking+Dummy', '~> 1.0'

 

exclude_files lets us leave out code we don’t want but other headers will still try to import it. So we make our own pod that contains empty headers with the same name and make AFNetworking depend on it.

To create our pod containing the dummy header file, make a directory called AFNetworking+Dummy and put a podspec file of the same name inside of it. It should have the following contents at a minimum:


Pod::Spec.new do |s|
s.name = 'AFNetworking+Dummy'
s.version = '1.0'
s.source_files = '*.h'
end

 

Now touch the file AFNetworking+Dummy/AFNetworking+UIImageView.h or otherwise create an empty file with that name.

Now you just need to update your Podfile so Cocoapods can find your dummy pod and your custom podspec.


pod 'AFNetworking+Dummy', :path => 'path_relative_to_podfile/AFNetworking+Dummy'
pod 'AFNetworking', :podspec => 'path_relative_to_podfile/AFNetworking.podspec'

 

Now you’re ready to use both RestKit and SDWebImage at the same time!

 

Written by hackingonempty

2014/04/03 at 2:40 am

Posted in ios, workarounds

Design a site like this with WordPress.com
Get started