I am trying to create a Singleton class, where I want to create an instance of UIImage.
In Objective-C
we can simple declare a property in .h like
@property (nonatomic,strong)UIImage *pic;
and define a sharedSingleton Method in .m
+(SingletonClass*)sharedSingleton{
@synchronized(self){
if (!sharedSingleton) {
sharedSingleton=[[SingletonClass alloc]init];
}
return sharedSingleton;
}
}
and call from any class with
[SingletonClass sharedSingleton].pic
I am searching from last 2 hours but didn't find ant suitable tutorial to create this. please help me out to create a singleton class in swift and tell me how to call the instance variable.