I have seen in a lot of standard Apple APIs and open source, custom APIs that an object can be declared as shared. For example, NSUserDefaults
is accessible by the method [NSUserDefaults standardUserDefaults]
and NSNotificationCenter
by [NSNotificationCenter defaultCenter]
. I was wondering how I could make one of my custom objects in an application shared, so the current instance of that object could be accessed via a method like [MyObject sharedObject]
?
I downloaded an application with this functionality, but the object that was shared only declared the method used to access the current instance of the object in the header file (.h), and there was no implementation of the method in the implementation file (.m).
It declared it by saying:
+ (GameObject *)sharedGameObject;
I know the plus means it is a class method, meaning that it does not require an instance of that class to be created, but can be accessed anyway, like CALayer
's [CALayer layer]
method.
I would appreciate any help! Thanks,
Ben