Similar to C #, OC also has a root type, that is, nsobject, which contains an alloc method and an init method. As the name implies, alloc is used to apply for memory, create an internal structure of an object, and assign the instance variable to 0.
The init method assigns the value of the variable to the default value (it seems to be different from 0), and then executes some other tasks.
Alloc is like entering a car, and init is a fire engine.
Normal Syntax:
Myobject * someobject = [[myobject alloc] init];
[Someobject dosomething];
The other is:
Myobject * someobject = [myobject new];
Write in this wayProgramExecute as usual
Myobject * someobject = [myobject alloc];
[Someobject dosomething];
Why? Because the init method defined in nsobject does not initialize anything, it only returns itself. Before the class is used, you need to execute some tasks to use, and init is only a placeholder for these tasks. Nsobject does not initialize anything, but the [[myobject alloc] init] method is still recommended. The initialization method returns an object of the ID type, therefore, the init method and alloc method may not return an object. This technique ([[myobject alloc] init]) is called two-stage creation.