在 AppDelegate 中,我正在分配一个在静态库中定义的实例。这个实例有一个 NSString 属性设置了一个“副本”。当我访问此实例上的字符串属性时,应用程序因“发送到实例的无法识别的选择器”而崩溃。Xcode 为该属性提供了代码提示,这意味着它在调用应用程序中是已知的。特定类被编译到静态库目标中。我错过了什么?
添加一些代码。
//static library
//ClassA.h
@interface ClassA : NSObject {
...
NSString *downloadUrl;
}
@property(nonatomic, copy) NSString *downloadUrl;
//ClassA.m
@synthesize downloadUrl;
在调用应用程序的 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/";
...}
应用程序中的其他类将获得对委托的引用并调用 classA.downloadUrl。