我正在尝试使用单例模式在对象周围传递数据。这是我的代码
搜索数据.m
@implementation SearchData
@synthesize theName = _theName;
-(id)init
{
if(self = [super init])
{
_theName = @"Default";
}
return self;
}
static SearchData *sharedSingleton = NULL;
+(SearchData *)sharedSearchData
{
@synchronized(self)
{
if (sharedSingleton == NULL)
{
sharedSingleton = [[self alloc]init];
}
return sharedSingleton;
}
}
@end
FirstView.m
...
-(id)init
{
if (self = [super init])
{
SearchData *data = [SearchData sharedSearchData];
self.aName = [data theName];
}
return self;
}
...
问题是我得到了
不兼容的指针类型将 NSString 发送到 NSStream 类型的参数。
这里有什么问题? 如何将数据传递给 aName ivar?
最佳答案
在你的 aName
声明中,你是否将 NSString
错误地输入为 NSStream
?奇怪的事情发生了。
关于objective-c - 对象间共享数据的单例模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9521347/