Understanding inheritance, mastering the use of his attributes and methods is also related to the initialization of the complete form, initialization method;; Traverse initialization,
1.oc the characteristics of Inheritance: (1) Inheritance in the previous layer when the parent class, the next layer is a subclass, the parent class and the child class is relative. (2) All classes are the most fundamental of the parent class is nsobject: The Ancestor (3) of the class inherits the transitive (4) Core: The subclass can inherit all of the parent class (except private) characteristics and behavior.
2. Inheritance: (1) enhance the reusability of the Code, reduce the development time of the Code, the implementation of the level of separation of code,
3. The use of inheritance, (1) after interface the class name: The parent class name inherits the implementation.
Note: (1) OC is a single inheritance, multi-implementation. There can be only one parent class, (2) before inheriting a class, you need to introduce the header file of that class first
4. Use of attributes between classes: Properties owned by a class, in addition to their own declarations, contain those attributes declared by the parent class.
4. Rewrite:
when the method of the parent class does not fully satisfy the requirements of the subclass, the method of the parent class is rewritten in the subclass, and the method can be substituted with the message sending mechanism of OC.
subclasses implement one or more of the methods in the parent class without declaring them and implementing them directly. The method name you implement must be exactly the same as the parent class. If it is not consistent, rewriting the beauty of success, this method becomes a private method.
5.isa NSObject provides an instance variable, which is a struct pointer that points to the information that holds the class. Usually do not manipulate, hide pointers,
6. Namespaces, to solve the problem of duplicate definition of the class name, OC is resolved by prefix, Apple retains the right to use all two letter prefixes.
7. Reserved words: Uncertain use, as a reservation, do not allow users to use,
8. Code specification, when writing classes and class methods, be sure to add comments, more comments.
9. Initialize the method: (1) assigns the value to the instance variable, guarantees the value the correctness.
Requirements: (1) The initialization method is used only once for the entire life cycle of the object. Life cycle: From create request to release. Can be called multiple times, not recommended to do, the possible values have changed. This is also why opening up space and initializing is usually written together to prevent repeated calls.
(2) The initialization of the execution process, before initialization, based on the number and type of instance variables of the object to request large enough memory. The initialization is based on the type of each instance variable in the allocated memory, the re-allocation of memory, initialization of the object.
The problem of incomplete initialization, (1) When initializing, requires that the instance variables of all objects of both themselves and the parent class be initialized. Easy to miss error-prone and incomplete, (2) Not necessarily fully aware of all the instance variables that all parent classes have.
10. The understanding of the complete body, the initialization method is to initialize the member variables to the instance variables, from the parent class instance variables to call the parent class method to initialize them, their own new instance variables are directly initialized.
11.self Super two keywords. Super : A compiler directive is not an object, it is the parent class of this class.
Self If it is in a class method, it is a class of its own, and if it is in an instance method, it represents the object that called the method.
12. Summary: Things to note in the initialization method:
(1) The type of the method is "-" (2) The return value of the method is (Instancetype) (3) that begins with Init and conforms to the hump naming method, which is recommended with. (4) Can take parameters, the number of Unlimited, (5) The complete wording, call the parent class initialization method, and use if to determine whether the call succeeds.
13. Convenient constructor, convenient initialization method: Spirit: Sacrifice The ego, the achievement of my own practice is: In the method directly completed Alloc and init.
(1) + method (2) starts with a lowercase class name and conforms to the hump naming method. + (Instancetype) Anminlwithname (3) in the method, the curly braces, the object is created to request memory Alloc and Inin, and the object's instance variable is initialized according to the value of the parameter, returning the current object.
(4) The function is to return an already initialized object, the creation and initialization of the object is done in the convenience constructor, external to consider.
(5) When called, convenient and convenient memory management, but in the class more code.
Through the class method, it realizes the fast acquisition of the class object,
10. Who pollutes who governs, who applies, who initializes.
oc3-initialization of complete form, initialization method; traversal initialization