We first assume that we have created a class now, and we are named MyObject, and inherit from NSObject. Inheritance know, it is you this subclass (MyObject) If you do not write anything, and the parent class (NSObject) is exactly the same. Almost all of the classes in OC are rooted in nsobject, adding member variables and functions on a nsobject basis. The parent class is not a class you write yourself, you can't guarantee it's safe, and you might not know what it's like in a successful initialization. self = [Super init], you may be difficult to understand this step of the way. Self points to the memory address that the parent class initializes. The initialization function of a class returns nil if it fails, and then self is nil. Then if (self = nil), your downward initialization work is done on nil and initialization fails. If you want to have a deeper understanding, look at the following paragraph: when the parent class initializes, with the subclass object pointer Self, the parent's Init method may make a large change to the memory area that the pointer points to (it is possible to release the memory that the pointer refers to, and reassign another chunk of memory to return, At this point the returned pointer is pointing to a different address than the original pointer, so the parent class is initialized to return the pointer again. The types returned by the parent class and the self of the subclass are of type ID (common type). The Init method of the parent class if the pointer returned is not the same as self, in the parent class Init method has been made release and new memory allocation, do not need to go to release self, directly with the parent class Init method returned by the pointer is possible. if (self = [super init]) {You can}return self as long as you know you need to initialize your work here;
There is no need for this in the base class, it is only used in subclasses. [Super Init] is initialized with the parent class to see if the parent class can be initialized, and if it cannot be initialized, the subclass cannot inherit the properties and methods of the parent class. This subclass is meaningless and cannot have properties of the parent class. So, in this place plus if (self = [super init]), is used to judge this. If you cannot inherit, you can return empty objects directly (meaningless).
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Objective-c language if (self = [super init])