15

When call setImageWithURL, it fails with following,

[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x149a20 2011-12-14 18:11:38.060 [781:707] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x149a20'

I can confirm I have included SDWebImage project and required headers correctly as I can use the SDWebImageManager successfully.

Following is the code where I called the UIImageView category method setImageWithURL

NSURL* url = [NSURL URLWithString:@"www.abc.com/abc.png"];
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"abc.png"]];    
Vlad Z.
  • 3,401
  • 3
  • 32
  • 60
Chim
  • 277
  • 1
  • 3
  • 9
  • Can you post the code of where you create the image and call the method so we can have a better idea of what might be going on ? – Mutix Dec 14 '11 at 23:58
  • Question has updated with requested info. Further, category is defined in UIImageView+WebCache.h file and i have included it in the same file as above code. Looks like this category function is not visible to UIImage view instance. Is there anything else need to be done other than including the header? – Chim Dec 15 '11 at 04:34
  • this is quite strange as your code looks fine, the error is really pointing to the category not being found. Are you sure you are importing the category properly? `#import "UIImageView+WebCache.h"` – Mutix Dec 15 '11 at 08:57
  • Yes, I had the import correctly. I used the source directly without refer it as a static library. Problem got solved that way. – Chim Feb 01 '12 at 12:09

13 Answers13

18

As per: linking objective-c categories in a static library

Due to a linker bug in XCode, you need to set the 'Other Linker Flags' setting your build target. Setting the flag as follows should eliminate this error.

-force_load ${BUILT_PRODUCTS_DIR}/libSDWebImage.a
Community
  • 1
  • 1
Steven Veltema
  • 2,140
  • 15
  • 18
  • I'm confused about how to add the files to the project. I copied the SDWebImage folder into my project's directory (via terminal). This includes the SDWebImage.xcodeproj file. Then I right click the project in Xcode and click 'Add Files...' which copies in the folder and all the contents, PLUS the .xcodeproj file which expands to the same files AGAIN in a folder structure, and the libSDWebImage.a file (red). I want to keep the file size down, so is this necessary? (I added the folder to my proj's header search paths) but get the above error even with Other Linker Flags set. *confused – Smikey Jan 23 '12 at 14:50
  • That's a little excessive. Just drag the SDWebImage.xcodeproj to your project. Set "Target Dependencies" and "Link Binary With Libraries" in the build phases of your project target. Finally, add the above flag to force the category to load. – Steven Veltema Jan 24 '12 at 05:43
  • 1
    If you are using ARC Compliant SDWebImage, you'll have to add the following line: -force_load ${BUILT_PRODUCTS_DIR}/libSDWebImageARC.a – averydev Aug 31 '12 at 20:13
  • 1
    has anybody tried this thing on xcode 4.5? I am not able to resolve the problem.. – user739711 Nov 02 '12 at 08:41
  • 2
    @user739711 yes i just resolved it for xcode 4.5, i added the arc framework in "target dependencies" but i had forgotten to add libSDWebImage.a (w/ arc support) to "link binary with libraries" – pulkitsinghal Nov 07 '12 at 05:08
  • Your saving my day, Thanks – majorl3oat Feb 26 '13 at 01:47
  • Im confused, are you saying drag the xcodeproj fileinto my project?? – Harry Mar 19 '13 at 10:10
  • This is for adding ZXing but the principle is the same. http://yannickloriot.com/2011/04/how-to-install-zxing-in-xcode-4/ – Steven Veltema Mar 20 '13 at 03:07
  • Where do I download the static lib from? – Dejell Mar 29 '13 at 11:01
  • It may have changed, but try here: https://github.com/rs/SDWebImage/wiki/Download-Complied-Framework – Steven Veltema Apr 17 '13 at 04:32
11

This will solve the problem: Open the "Build Settings" tab, in the "Linking" section, locate the "Other Linker Flags" setting and add the "-ObjC" flag: enter image description here

Hossam Ghareeb
  • 7,063
  • 3
  • 53
  • 64
9

If anyone, like me, still has problems after seeing all the other answers here (e.g. force_load or load_all) even after following all the proper installation instructions, here is what I have learnt after doing some search online:

  • This problem only happens when you use iPhone 5S or the 64-bit simulator
  • This is a problem with libwebp

The solution to this problem: Only do this if you don't need the 64-bit processor for your app (too new to iOS programming to know if this sentence is valid)

  1. Go to build settings > Architecture

  2. Under Architecture, select Standard architectures (armv7,armv7s)

  3. Under Build Active Architecture Only, make sure it is Yes for both Debug and Release

My source: https://github.com/rs/SDWebImage/issues/494

I hope this helps those who, like me, found this while trying to solve your problem =)

SilverHood
  • 713
  • 1
  • 8
  • 15
  • 1
    Tried everything in this thread. The only thing that have worked for me. Seems to run fine on the 64bit emnulator nontheless. – Vaiden Feb 23 '14 at 04:18
6

I ended up inserting all the .h and .m files into my project and then it worked fine. I got the same error when I only included the .a and .h files.

Christian Loncle
  • 1,584
  • 3
  • 20
  • 30
  • I managed to solve the problem the same way.This is not the best way to solve the issue but need to verify force_load attribute mention by Steven. – Chim Feb 01 '12 at 12:10
  • @chrizz Even I am facing the same issue.I have included all the SDWebImage files to my project, no header settings done.I know i m missing something here. Kindly point me where i m wrong. Thanks. – aToz Jul 25 '12 at 06:58
  • 4
    I Solved the same problem adding the libSDWebImage.a to Build Phases > Link Binary with Libraries – gcstr Dec 08 '12 at 21:54
  • Where do you add libSDWebImage from? – Dejell Mar 24 '13 at 21:16
  • You need to add all the .m files. that would fix the problem – barryjones Mar 28 '13 at 02:39
  • I did. But I still have this problem – Dejell Mar 29 '13 at 09:47
  • @Odelya Were you bale to solve it? Added all the .h and .m files, but couldn't solve the problem. Neither did I find where the .a file is. Is the .a file generated when the SDWebImage source code is compiled? Neither Did I get it that way. – Ravi Vooda May 08 '13 at 13:52
  • I had a different problem - the tag of the item that I wanted to check wasn't an UIImageView – Dejell May 08 '13 at 13:54
4

In the SDWebImage docs, it says that you have to set "Other Linker Flags" to -ObjC. This did not work for me. Instead, I set it to -all_load. I also had to remove -ObjC. The explanation for what is going on can be found here:

http://developer.apple.com/library/mac/#qa/qa1490/_index.html

It also explains why -ObjC fails: "Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the f-all_load or -force_load flags"

Using -all_load increases the size of the executable. You can use -force_load to mitigate this somewhat. For SDWebImage 2.7.3, I did this by setting the following in "Other Linker Flags" in the Build Settings: "-load_all $(SRCROOT)/SDWebImage.framework/SDWebImage". Linking to libSDWebImage[ARC].a which is what some sources advise, didn't work for me.

Incidentally, in Xcode 4.4, it seems you have to do a slow double-click in order to change build settings properly. Doing a normal double-click shows the completely screwed up and non-working pop-up.

Andz
  • 1,315
  • 1
  • 12
  • 14
2

Solved the same problem adding the libSDWebImage.a to Build Phases > Link Binary with Libraries.

Rajesh Maurya
  • 3,026
  • 4
  • 19
  • 37
1

If you read the document here https://github.com/rs/SDWebImage at the bottom there is a download link with the CORRECT files to download. Following that example it works perfectly.

The mistake I made, and seemingly others to, is I downloaded the github project and tried using that.

Harry
  • 13,091
  • 29
  • 107
  • 167
1

Everything started to work for me once I linked "ImageIO.framework" to my main project.

ingh.am
  • 25,981
  • 43
  • 130
  • 177
0

You can also set 'Other Linker Flags' to -all_load. This solves the problem where an external framework (such as the filepicker framework) requires linking against SDWebImage.

filitchp
  • 616
  • 9
  • 8
0

-force_load is not fix fundamental problem (when achiveing problem happens) to fix this linking problem..

  1. edit scheme for SDWebImage,
  2. run scheme set for release
  3. run (with device)
  4. libSDWebImage.a will be generated in release-iphoneos directory.
  5. set target->BuildPhase->link Binarywithlibrary .. add this lib.
  6. Done..
Mark Yang
  • 226
  • 3
  • 16
0

Make sure your compiled files have UIIMageView+AFNetworking.m in case you're using AFNetworking framework.

Nosayr Yassin
  • 419
  • 1
  • 6
  • 15
0

You need to add the libSDWebImage.a in your linked binaries, also check for other linker flags, it should be -ObjC

Jasveer Singh
  • 354
  • 3
  • 10
0

Checkout your choice when you pull files of SDWebimages into Xcode, do mark the "create groups" in added folders, and do not mark the "create folder references".

Mark exactly as the picture:

enter image description here

user3071284
  • 6,955
  • 6
  • 43
  • 57
mob
  • 1
  • 1