Can Someone explain me few things regarding the Singleton implementation in Apple’s documentation here.
Go to Creating a Singleton Instance in the link.
I tried but couldn’t understand few things:-
- What does [super allocWithZone:NULL] in + (MyGizmoClass*)sharedManager does.?
- Why does allocWithZone call sharedManger method and return a retain call on its return type when retain itself returns self ?
- If the Singleton has some instance variables in it, where should they be initialized ?
If anyone could briefly explain working of allocWithZone and sharedManager methods here , a lot of these questions would automatically be answered.
That implementation is generally considered over_kill. There is a lot of protections against a programmer trying to mis-use the singleton which is generally not considered necessary.
Here is an example of a more simple implementation from Yoga: