我試圖使用單例模式傳遞對象周圍的數據。這裏是我的代碼用於在對象之間共享數據的單例模式
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.
這裏有什麼問題? 如何將數據傳遞給名稱ivar?
是啊... aName被宣佈爲NSStream代替的NSString – OhDoh 2012-03-01 18:00:05
真棒!很高興我能幫上忙。您可以點擊左邊的小複選標記將答案標記爲已接受。非常感謝! – QED 2012-03-01 18:05:00