With the help of good people here, i was able to write a singleton but cant get the delegates from it.
At the start i had a socketConnector
class and from the Home
class, i made an instance of him, and also got a delegates from him :
socketInstance=[[SocketConnector alloc]init]; //in Home class
socketInstance.delegate=self;
Than i needed to create a singleton for him, and STILL get the delegates from him to Home
.
so i created a singleton class name : sharedConnector
and in it i have :
+(sharedConnector*)defaultConnector
{
static sharedConnector *myConnector ;
@synchronized(self)
{
if( myConnector==nil )
myConnector=[[sharedConnector alloc]init ];
return myConnector;
}
}
- (id)init
{
if (self = [super init])
{
connector=[[SocketConnector alloc]init]; //setting here the socketClass
}
return self;
}
as you see i am setting here the socket class once , than to use it from Home
class:
[sharedConnector defaultConnector].connector.delegate=self; //setting delegates to home!
(connector has a property on the singleton) it do work , but i dont get the delegates to home anymore . (all the delegates functions are still in Home class as they where at the start )