attribute Nature
• What is a property
In OC, attributes provide a setter and getter method, which is essentially a method, and the value of the property is saved by an instance variable.
• Nature of attributes (typically three parts)
A. Saving an instance variable of a property value int _age;
Declaration of the B.setter and Getter methods
1.) Setter Method: Method name + "Set" + attribute name and first parent capital + ":" + and attribute type parameter, no return value.
-(void) Setage: (int) newage;
2.) Getter? Method: Like the method name and the property name, there are no parameters, and the return value type is the same as the property type.
-(int) age;
Implementation of C.setter method and getter method
The implementation of setter methods is mainly used to assign values to attributes ; object. property = value ==> automatically calls the Setter method
The implementation of the Getter method is primarily used to read property values ; a variable = Reference. Property;=> automatically calls the Getter method
Stu.age = 18;//assigns a value to a property setter!
NSLog (@ "age:%d", stu.age);//Fetch property value getter
• Declarative Properties
A. Defining instance variables
B. Declarative properties
1). h file int attribute type age property name, automatically generated setter and getter
@property int age;
2). Associates a property with an instance variable. m file
@synthesize age = _age;
C. Use of attributes
Reference. property = value;=> automatically calls the Setter method
Variable = Reference. Property;=> automatically calls the Getter method
The declaration of attribute properties in iOS5 simplifies the
A. Omit instance variable declaration, automatically generate instance variable named: _ Property Name
B. Declarative properties
1). h? file int attribute type age property name, automatically generated setter and getter!
@property int age;
2). Associates a property with an instance variable in the. M-piece!
@synthesize age = _age;
The declaration of attribute properties in IOS6 simplifies the
A. Province
B. 1) Retention
2) Province @synthesize age = _age;
C. Retention
D. The evolution of properties, if you are not satisfied, you can rewrite.
Initialize Method
• What is the method used by the initialization method to initialize an object.
• Uninitialized initialization method initialization? Methods are all beginning with "Init", and the parameterless initialization method is called "Init".
• The parameter initialization method has a parameter that begins with "Initwith ...".
ID type initialization? The return value of the method is the "id" type. (void*)
The self keyword self represents the current object or the current class, and self is a reference to the current object.
(address) Initialization method Super The keyword Super Represents the parent class of the class, [Super Init] is to notify the parent class to do the underlying initialization operation.
Class method
• What is a method called by a class method that can only be called by a class method. +
• Definition of class method, class method and instance method difference
A. Instance methods are related to instances, so instance methods can invoke, read instance variables or properties in an instance.
B. Class methods are not related to instances, so class methods cannot invoke, read instance variables and properties in instances.
C. In a class method, you can create an object that accesses the instance variables and properties of the object.
Factory method
• What is a factory method for producing (creating) objects, called a factory? method. Classes often appear in the factory method, which is designed to facilitate the creation of objects.
• Non-parametric factory method The method name of the factory method must begin with the class name, taking care to remove the prefix and the first letter to lowercase.
• Factory method With reference
Objective Note C (next day)