Alexander Farber
Alexander Farber

Reputation: 23038

SDWebImage in a simple test app crashes with NSInvalidArgumentException

In Xcode 5.0.2

  1. I create a blank single view app for iPhone,
  2. then add a "male.png" image to the project,
  3. drag a UIImageView to the storyboard
  4. and finally add the following code to the viewDidLoad:

    _imageView.image = [UIImage imageNamed:@"male.png"];

This works well:

simulator screenshot

Then I add the files from SDWebImage project and change the ViewController.m to:

#import "ViewController.h"
#import <SDWebImage/UIImageView+WebCache.h>

static NSString* const kAvatar = @"http://gravatar.com/avatar/55b3816622d935e50098bb44c17663bc.png";

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [_imageView setImageWithURL:[NSURL URLWithString:kAvatar]
               placeholderImage:[UIImage imageNamed:@"male.png"]];
}

@end

Unfortunately, this results in app crash with the error message:

2014-01-11 19:21:57.731 sdImage[2563:70b] -[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x8a5aa80
2014-01-11 19:21:57.745 sdImage[2563:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 0x8a5aa80'
*** First throw call stack:
(
    0   CoreFoundation                      0x017395e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x014bc8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x017d6903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0172990b ___forwarding___ + 1019
    4   CoreFoundation                      0x017294ee _CF_forwarding_prep_0 + 14
    5   sdImage                             0x00002b43 -[ViewController viewDidLoad] + 227
    6   UIKit                               0x0033e318 -[UIViewController loadViewIfRequired] + 696
    7   UIKit                               0x0033e5b4 -[UIViewController view] + 35
    8   UIKit                               0x002669fd -[UIWindow addRootViewControllerViewIfPossible] + 66
    9   UIKit                               0x00266d97 -[UIWindow _setHidden:forced:] + 312
    10  UIKit                               0x0026702d -[UIWindow _orderFrontWithoutMakingKey] + 49
    11  UIKit                               0x0027189a -[UIWindow makeKeyAndVisible] + 65
    12  UIKit                               0x00224cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
    13  UIKit                               0x002293a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    14  UIKit                               0x0023d87c -[UIApplication handleEvent:withNewEvent:] + 3447
    15  UIKit                               0x0023dde9 -[UIApplication sendEvent:] + 85
    16  UIKit                               0x0022b025 _UIApplicationHandleEvent + 736
    17  GraphicsServices                    0x036e02f6 _PurpleEventCallback + 776
    18  GraphicsServices                    0x036dfe01 PurpleEventCallback + 46
    19  CoreFoundation                      0x016b4d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    20  CoreFoundation                      0x016b4a9b __CFRunLoopDoSource1 + 523
    21  CoreFoundation                      0x016df77c __CFRunLoopRun + 2156
    22  CoreFoundation                      0x016deac3 CFRunLoopRunSpecific + 467
    23  CoreFoundation                      0x016de8db CFRunLoopRunInMode + 123
    24  UIKit                               0x00228add -[UIApplication _run] + 840
    25  UIKit                               0x0022ad3b UIApplicationMain + 1225
    26  sdImage                             0x00002ffd main + 141
    27  libdyld.dylib                       0x01d7770d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Why does it happen please? While adding the framework files I have set the checkbox to copy the files.

UPDATE:

I have also tried the following:

git submodule add https://github.com/rs/SDWebImage.git

then built that project (SDWebImage.xcodeproj) and closed it.

Then I have reopened in Xcode my project (sdImage.xcodeproj) and dragged the SDWebImage.xcodeproj file into it.

After that I have tried to add a Target Dependency, but it doesn't show anything named "SDWebImage" there:

screenshot

Here the full sized screenshot.

And I can not add an "SDWebImage.framework" under Link Binary With Libraries, because nothing named "SDWebImage" is there.

Upvotes: 0

Views: 1333

Answers (2)

bgfriend0
bgfriend0

Reputation: 1152

Why don't you just include the SDWebImage source files in your main project? This is how I incorporated SDWebImage, and the SDWebImage docs themselves state: "There are two ways to use this in your project: copy all the files into your project, or import the project as a static library." If you do this there is no need to open the SDWebImage project, compile the framework, link the framework with your project, etc.

Upvotes: 2

Alexander Farber
Alexander Farber

Reputation: 23038

I've got the project by using CocoaPods with the following Podfile:

platform :ios, '5.0'
pod 'SDWebImage'

and then running pod install and opening sdImage.xcworkspace in Xcode.

I'm still interested in how to use SDWebImage in a project - without using CocoaPods...

Upvotes: 0

Related Questions