MBSingleton Protocol Reference
| Conforms to | NSObject |
|---|---|
| Declared in | MBSingleton.h |
Overview
Adopted by classes that act as singletons.
Singletons will only ever return a single object pointer over the running lifetime of an application.
Because the singleton is guaranteed not to change, it is safe for callers to
store long-term references to it. This way, the overhead incurred by
unnecessary repeat calls to the singleton’s instance method can be avoided.
If a class implementation might return more than one distinct object pointer
over the lifetime of an application, it should adopt the MBInstanceVendor
protocol instead of MBSingleton.
Automatic singleton implementation
Mockingbird provides the MBImplementSingleton() macro for classes that do
not wish to provide their own implementation of the instance method.
MBImplementSingleton() expands to a thread-safe, lazily-instantiated
implementation of the instance method.
To use, place the macro between the @implementation…@end keywords of the
singleton class’s implementation.
Note: Singleton implementations should strive to be thread-safe. If a class adopting this protocol is not thread-safe, that fact should be noted prominently in the class’s documentation.
+ instance
required method
Retreives the singleton instance of the receiving class.
+ (instancetype)instanceReturn Value
The singleton instance. This value should never change during the running lifetime of the application.
Declared In
MBSingleton.h