Protocol for implementing singleton objects in mulle-objc. Provides thread-safe singleton initialization and access.
+sharedInstance
- Get singleton instance
+initializeSingleton
- Initialize singleton instance
MulleObjCInstanceIsaSingleton
- Check if instance is singletonMulleObjCClassIsaSingleton
- Check if class is singleton
@interface MySingleton : NSObject <MulleObjCSingleton>
@end
@implementation MySingleton
+ (instancetype) sharedInstance
{
return( MulleObjCSingletonCreate( self));
}
+ (void) initializeSingleton
{
// Initialize singleton state here
}
@end
// Usage
id instance = [MySingleton sharedInstance];
-
Thread Safety
- Thread-safe initialization
- Safe instance access
- Handle concurrent calls
- Consider TAO rules
-
Initialization
- One-time setup
- Handle dependencies
- Clean up properly
- Check state
-
Best Practices
- Lazy initialization
- Handle errors
- Document usage
- Test thoroughly
-
Performance
- Cache instance
- Minimize locks
- Consider inlining
- Handle contention
Note: This protocol provides thread-safe singleton implementation. The singleton instance is created lazily on first access and guaranteed to be initialized only once.