Class: A class is an abstract concept that has the same attributes and behavior as a class of elements.
Distinguish between a class or an object to see if it can continue to be subdivided.
In OC, a class is a struct that represents an object type, and an object obtains various information about itself through a class. The class consists of two parts: *.h and *.m files.
The implemention part of the *.M file is the implementation part of the class, which contains various information from the class, including various instance methods or class methods.
Category: Is the way to add a new method to an existing class, typically named by class name + category name.
You cannot add a new instance variable in a category. However, you can add properties to the category.
The main purpose of a category in business development is to add a new method to a class without changing the original content of the source code.
Class extension: Class extensions are a special form of classification, and extensions are categories with no names. File is usually: "The main class class name _ extension identity. h"
Extensions are typically defined in the. m of the file, and cannot be separated. An extension can declare instance variables, properties, methods, but all are private methods.
Object: It is not subdivided and represents something specific.
In OC, an object is a struct that contains a value and a hidden pointer to its class.
By instantiating a class into an object.
The methods of instantiation are Alloc,new,copy, factory method, single case method, etc.
Instance variable (instance variable): A variable of the instance session defined by the class (excluding the base data type, such as Int,double,float).
Member variables (Member variable): Variables in code, including instance variables and basic variable types, without contact with the outside world.
The member variable is protected by default, and in general, non-subclass objects cannot be accessed.
Property: The compiler automatically reads the composition of the variable's set and Get methods, the available point syntax, and can be used as a variable to contact the outside world.
To differentiate between instance variables and member variables:
You can see that in the interface @interface parentheses are collectively referred to as "member variables", the instance variable is one of the member variables! The English translation of the instance variable is the Instance Variable (object-specificstorage) instance of the English translation of Instance (manifestation of a class) is said to be "the manifestation of the class", The description instance variable should be a variable defined by the class! Remove basic data type int float .... And so on, other types of variables are called instance variables. * * Instance variable + basic data type variable = member Variable * *
in the @property (description 1, description 2, Description 3) (class *) VarName , there are 3 descriptive words to fill in (also can not fill in the default values)
1. Nonatomic<-->atomic
2. Readwrite<-->readonly
3. Retain/copy/assign
let's start by introducing:
retain
: He refers to assigning a pointer to a memory area to a variable and adding 1 to the reference counter for that memory area. Each time the memory region's reference counter is incremented by 1, the memory area is freed when the reference counter of that zone becomes 0!
Copy
: It refers to copying the value of the target memory area and then opening up a new memory area (new pointer) to paste the value. The variable is assigned a pointer to the new memory area!
Assign: It means that only the pointer to the target memory area is assigned to the variable, and the reference counter of that memory area does not change!
1, 22 points do not explain, 3 of retain, copy, assign all refers to, in the automatic generation of setter function, the compiler needs to identify a description of the word to generate corresponding setter function! It is important to note that if you do not add the class descriptor, the system defaults to the variable's setter method to take a assign approach. In the header file. h typically has a defined instance variable in {}Example:. h@property (automic,retain) nsstring * ABC;. M@sythesize ABC;
//In the case of writing a @sythesize ABC, the system instance variables are not automatically generated "_ ABC ", directly through the variable name ABC , that is, directly using the variable name in the assignment operation (= number to the left), just assign the memory area pointer to the variable, equivalent to Assgin. If you are assigning a value through the "point statement" self.abc=, it is necessary to see what kind of copy, retain, assign are defined in @property, and if you do not add the above description, the default is assign.
If you do not write @sythesize ABC, the system will automatically add an invisible member variable with "_" in the. h file {} By default (even if the variable name itself has "_")
//parentheses define the member variables (base data type + class-generated variable), the variables in the. m file can be accessed directly into the parentheses by "variable name", "self->" variable name, but such assignment access can only be assign, The reference counter for the original object does not change.
[email protected] variable name; [email protected] Variable name =_ variable name; 3. Do not write @sythesize (refer to the variable names mentioned in the header file @property defined in the variable)
1. Member variable, the instance variable is directly accessed by the "variable name" or self-> "variable name", Assignment (assign). Self. Variable name implementation Setter,getter method.
2. Member variable, the instance variable is directly accessed by "_ Variable name" or self-> "_ Variable Name", Assignment (assign). self. Variable name implementation Setter,getter method.
3. member variables. Instance variables (the system automatically adds "_" to the original variable name to generate the instance, member variable), directly through the self->_ variable name, or variable name directly to (assign). self. Variable name implementation Setter,getter method.
If there are no variables defined through @property in the header file, but there are defined member variables in the {} and no @sythesize in the implementation file, you can either go directly to the variable name in the Self-> "{}" or use "{}" directly. To access the assignment, such a variable does not define the Setter,getter function and can only be assigned in the Assign way.
Again to analyze the wording in @sythesize, @sythesize ABC directly in the. m file using SELF.ABC can call the member variable setter, getter function, directly call the member variable name ABC is to access the variable pointer, Assigning a value directly to a member variable is equivalent to the Assign effect.
http://blog.csdn.net/wangtianyong0/article/details/50472041
Differences and relationships between classes, objects, instance variables, member variables, attribute variables, and so on in iOS development