1. Integration of a macro
2. Two sentence Code integration single case
3. One line of code calls a single case
------------->
1. Integration of a macro
Here to pay attention, because each singleton, the method name can be different, then we can't write the name to die, to flexible customization, then the call to him Bogwang Ah, then!!! Note that the join symbol # #的使用, the passed in parameters should be placed after the connection symbol as follows
#define IVANSINGLETONH (name) + (instancetype) shared# #name;
Note here, the general macro will only judge the name of the macro followed by the paragraph is its code, so add \ symbol to tell him that the next line is also the code he manages
#pragma note that this type is written as an ID type because the singleton it receives is of different types
#define IVANSINGLETONM (name) \
Static ID _# #name; \
\
+ (Instancetype) Allocwithzone: (struct _nszone *) zone\
{\
Static dispatch_once_t oncetoken;\
Dispatch_once (&oncetoken, ^{\
_# #name = [Super allocwithzone:zone];\
});\
return _# #name; \
}\
+ (instancetype) shared# #name \
{\
Static dispatch_once_t oncetoken;\
Dispatch_once (&oncetoken, ^{\
_# #name = [[Self alloc]init];\
});\
return _# #name; \
}\
-(ID) Copywithzone: (Nszone *) zone\
{\
return _# #name; \
}
2. Two sentence Code integration single case
Write a code for the. h file of the coded area of the single example:
Ivansingletonh (name), name write the singleton method name that you actually want to invoke
Write a code in the corresponding. m file:
IVANSINGLETONM (name), name write the method name of the singleton that you actually want to invoke (and the name of the. h file above is the same)
3. One line of code calls a single case
In the case where you want to invoke the singleton, import the header file of the singleton:
#import "ClassName.h"
Calling code:
[ClassName ShareName];
IOS-----Write a canonical list of--->