我正在尝试使用单例模式在对象周围传递数据。这是我的代码
SearchData.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;
}
...
问题是我得到了
Incompatible pointer types sending NSString to parameter of type NSStream.
这是怎么了?
如何将数据传递给aName ivar?
最佳答案
在aName
声明中,您是否将NSString
键入为NSStream
?发生了奇怪的事情。