Resolving the conflict between AFNetworking and SDWebImage
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!
[…] With a Google search, the only mention of the problem I could find was at https://hackingonempty.org/2014/04/03/resolving-the-conflict-between-afnetworking-and-sdwebimage/ […]
RestKit and SDWebImage interfere with eachother
2014/08/13 at 9:38 pm