Initialization method in single-instance mode for iOS development
The general one, we'll write it this way.
+ (Instancetype) sharedxxxmanager{StaticXxxmanager *sharedxxxmanagerinstance =Nil;Static dispatch_once_tpredicate;dispatch_once(&predicate,^{sharedxxxmanagerinstance = [[Xxxmanager alloc] initprivate]; });returnSharedxxxinstance;}
Here in general we will use a private initialization method, where the specified initialization method of the parent class is called.
-(Instancetype) initprivate{ Self= [Super Init];if( Self) {//init}return Self;}
and to prevent people calling the class from using the Init method , you can override the Init method and throw an exception to remind him that it is a single case.
-(instancetype)init{ @throw [NSException exceptionWithName:@"Singleton" reason:@"Use +[XXXManager sharedXXXManager]" userInfo:nil]; nil;}
Initialization method in single-instance mode for iOS development