The Init method of the parent class must be called by the custom Init method. Generally:-(ID) init{[super Init]; xxx = xxx;} Typically, this pattern can satisfy the overwhelming majority of requirements, but in a few cases, special handling is required. 1, for optimization reasons, the Init method frees the object that has already been allocated memory, and then creates another new object and returns it. The 2,init method has an error during execution, so the object is freed and nil is returned. For 1, Apple's approach is to give the parent Init method The return value to self, for 2, Apple's official website is to detect whether the parent class returns the object is nil, nil does not need to continue. So, Apple's recommended init customization method is:-(id) init{self = [super init]; if (self) {xxx = xxx; } return self;} In init, you can assign values directly, or you can use the access method. People who prefer direct assignment think that an object can be initialized only after the Init has been executed. People who prefer to use access methods think that the access method can do other things besides assigning values to instance variables. You can use the access method whenever you set an instance variable.
iOS Development Init method parsing