The singleton pattern ensures that a class has only one instance, and instantiates itself and provides this instance to the system as a whole.
Here the main introduction under ARC, the use of GCD to achieve a single case. First step: Declare a static instance static Soundtool *_instance; Second Step: overriding initialization method + (ID) allocwithzone :(struct _nszone *) zone This method is called when the object is initialized to allocate memory, and when overridden, even if the user does not use the shared method to obtain the instance, its initialization can still guarantee that the same instance will be obtained. After GCD, multithreading ensures that a code is only executed once to provide a convenient way to be dispatch_once. This code method does not need to be carefully memorized. The code snippet has been built into Xcode. When you knock down the dispath_once, you'll have smart hints. Step Three: Declare a class method shared instance + (Soundtool *) sharedsoundtool @implementation Soundtool static soundtool *_instance; + (Soundtool *) sharedsoundtool { static dispatch_once_t oncetoken; Dispatch_once (&oncetoken, ^{ _instance=[self new];& nbsp }); return _instance;} + (ID) allocwithzone: (struct _nszone *) zone{ static dispatch_once_t oncetoken; Dispatch_once (&oncetoken, ^{ _instance=[super allocwithzone:zone]; & nbsp }); Return_instance;} @end