A Singleton class returns the same instance no matter how many times an application requests it.
Example: UIApplication, UIAccelerometer, NSFileManager etc
For making our custom class(say Car) as singleton we need to create a class method as below:
+(id)sharedCar{
static id singleInstance=nil;
if(singleInstance==nil){
singleInstance =[[Car alloc]init];
}
return singleInstance;
}
Example: UIApplication, UIAccelerometer, NSFileManager etc
For making our custom class(say Car) as singleton we need to create a class method as below:
+(id)sharedCar{
static id singleInstance=nil;
if(singleInstance==nil){
singleInstance =[[Car alloc]init];
}
return singleInstance;
}
No comments:
Post a Comment