Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve 'unrecognized selector sent to instance'?

In the AppDelegate, I'm alloc'ing an instance defined in a static library. This instance has an NSString property set a "copy". When I access the string property on this instance, the app crashes with 'unrecognized selector sent to instance'. Xcode provides a code hint for the property, which means it is known in the calling app. The particular class is compiled into the static library target. What am I missing?

Adding some code.

//static library  //ClassA.h @interface ClassA : NSObject { ... NSString *downloadUrl; } @property(nonatomic, copy) NSString *downloadUrl;  //ClassA.m @synthesize downloadUrl; 

In the calling app's appDelegate.

//app delegate header file @interface myApp : NSObject <UIApplicationDelegate> { ClassA *classA; } @property (nonatomic, retain) ClassA *classA;  //app delegate .m file @synthesize classA;  - (void)applicationDidFinishLaunching:(UIApplication *)application { classA = [[ClassA alloc] init]; //exception occurs here.  downloadUrl is of type NSCFNumber classA.downloadUrl = @"http://www.abc.com/"; ...} 

Other classes in the app will get a reference to the delegate and call classA.downloadUrl.

like image 732
4thSpace Avatar asked May 14 '09 04:05

4thSpace


People also ask

What does unrecognized selector sent to instance mean?

I'm probably getting the terminology wrong, but “unrecognized selector” means you're asking an Objective-C object or class to run a function that it doesn't implement. (

What is #selector in Swift?

Use Selectors to Arrange Calls to Objective-C Methods In Objective-C, a selector is a type that refers to the name of an Objective-C method. In Swift, Objective-C selectors are represented by the Selector structure, and you create them using the #selector expression.


2 Answers

1) Is the synthesize within @implementation block?

2) Should you refer to self.classA = [[ClassA alloc] init]; and self.classA.downloadUrl = @"..." instead of plain classA?

3) In your myApp.m file you need to import ClassA.h, when it's missing it will default to a number, or pointer? (in C variables default to int if not found by compiler):

#import "ClassA.h".

like image 60
stefanB Avatar answered Oct 13 '22 23:10

stefanB


Set flag -ObjC in Other linker Flag in your Project setting... (Not in the static library project but the project you that is using static library...) And make sure that in Project setting Configuration is set to All Configuration

like image 28
Mihir Mehta Avatar answered Oct 13 '22 23:10

Mihir Mehta