1. How do I declare a class?
Format:
1 @interface People:nsobject 2 {3 // instance Variable 4 }5 // declaration of class 6@end
Attention:
- Must start with @interface and end with @end.
- The declaration of the member variable must be written in curly braces between @interface and @end
- The declaration of the method must be under {} and cannot be written in {}
2. How do I implement a class?
Format:
1 @implementation people 2 // implementation of the class 3 @end
Attention:
- 1. Must start with @implementation, @end end
- 2. The class name must be consistent with the declaration
3. How do I create an object?
Example: people * p = [people new]
Attention:
[People new] has done three things:
- Opens up a new piece of storage space in heap memory
- Initializing a member variable (a property written in a class declaration brace is called a member variable, also known as an instance variable)
- Return pointer address
4. Points of attention of the object:
-
- You can access the members of an object by using object-by-member (notice that the declaring property is: @public).
- Each object has a property of its own.
- A member of one of the objects was modified. Not related to another object
First OC Class