The singleton patterns of all programming languages are similar. Object-c, Java, C + +, and so on, with the language does not have much to do with the grammar, only a little relationship. In iOS if you have a class: Accountmanager, you want to define a singleton then the footwork is as follows: one. In the. h file there should be a definition similar to the following: + (ID) sharedinstance; Two. Within the. m file the class should have the following definition://declares a globally unique static object, also Accountmanager type static Accountmanager * _sharedinstance;//method implementation + (ID) sharedinstance {@synchronized ([Accountmanagerclass]) {if (_sharedinstance = = nil) {_sharedinstance = [[ ACCOUNTMANAGERALLOC] init];}} Return_sharedinstance;} Three. If you want to use the singleton in another class object and call a method of the singleton (todosomething): [[Accountmanager sharedinstance] todosomething]; additional instructions: 1. Sharedinstance This name is what I used to use, you can use another name, any, in short, to keep accountmanager This class can only have one instance 2 during the entire application run. The example here gives you a "lazy" singleton, as well as an additional singleton to complete the task, such as "A Hungry Man type" singleton. If you don't know what a lazy and a hungry man you can find on Google
IOS Singleton mode