1, the concept of a single case
A singleton that indicates that an object of this class can only be instantiated once in an application's declaration cycle, meaning that a class can have only one object.
2, the role of a single case
Because, in an application, a class has only one singleton object, so whether it's A or B or ... , as long as it is instantiated, it is the same object. So we can use this object to pass the value. (For example: This object has n properties, one of which is a rank, and we assign a value of x to the class attribute of the object in a, so wherever it is instantiated, the value of its rank attribute is x, which we can use).
3. How to use
A, new class of inheritance and NSObject:singleclass
b,. h files
C,. m files
D
// The use of singleton classes
singleclass *singleone = [singleclass shareinstance];
Singleone. name = @ " single case A";
NSLog(@ "%@", Singleone. Name);
singleclass *singletwo = [singleclass shareinstance];
NSLog(@ "%@", Singletwo. Name);
Although Singletwo is not assigned, it is also @ " Singleton A".
// print address
NSLog(@ "One address :%@ address :%@", singleone,singletwo); same address
IOS-Singleton mode