我正在尝试使用单例模式传递对象周围的数据。这是我的代码
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?
答案 0 :(得分:2)
在您的aName
声明中,您是否将NSString
误认为NSStream
?发生了奇怪的事情。
答案 1 :(得分:0)
因为searchdata(NSStream)没有进入NSString。 尝试:
[[NSString alloc] initWithData:searchData ...