1

IOS - singleton mode

2 months ago from

What is singleton mode

The so-called singleton mode means that there is only one instance variable in this class in IOS programs. No matter how many times it is created, it is the same object. For example, we have created a text object in a controller, and the properties of this object are the same in each controller. When we need to create it in another controller, it will appear redundant. At this time, we can use the design pattern of singleton.

Create method - this method is usually called by writing the share + class name in the. H file. The creation of singleton mode generally does not need to be called by alloc and init.

Note here:

Simple usage of static:

  1. Local variables can be modified and stored in static storage area.

  2. Global variables can be modified to restrict that global variables can only be accessed in the current source file.

  3. You can modify the function to limit that the function can only be called in the current source file.