I know there are several threads on this, but none answer my questions.
I\'ve implemented my singleton class like this (being aware of the controversy about singleto
@VeryPoliteNerd just mark the init
and new
methods as unavailable on the .h
:
- (instancetype)init __attribute__((unavailable("Use +[MyClass sharedInstance] instead")));
+ (instancetype)new __attribute__((unavailable("Use +[MyClass sharedInstance] instead")));
This will cause the compiler to complain if a caller tries to manually instantiate this objects