[ios development] Singleton mode

1. What is the singleton mode?
The singleton is equivalent to a global variable in the entire project, that is, wherever you need to use the instance variable of this class, you can get it through the singleton method, and once you create a singleton class, no matter how many you are in This singleton method is called to get the object by initialization in the interface, and all of their objects point to the same memory storage space (that is, the singleton class ensures that the instance object of this class is the only one that exists).

2. Complete example analysis by simply rewriting the demo of the alloc function:
Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here

This is described in the crazy ios handout:
Insert picture description here
Insert picture description here

Simply put, the purpose is to create an object once and use it in multiple places. This demo just created a singleton mode object and then completed the exercise of the singleton mode object by rewriting the alloc function

Guess you like

Origin blog.csdn.net/m0_46110288/article/details/108783406