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.
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. (
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.
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"
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With