To create a new class
New file->cocoa Class (parent class NSObject)
. h files are used to define properties and methods
. m files are used to specifically implement
Method declaration:
1 #import <foundation/foundation.h>2 @interface person:nsobject{3 nsstring *name;4 int age;5 NSString *address; 6} 7-(void) usetools; method declaration without parameter return value 8-(void) SetName: (NSString *) AName Age : (int) aAge; Declaration of a parameter without a return value 9 @end
1. Age is a label that describes the function of the following functions
2.-Symbol, for instance method, must instantiate an object, call with Object
The + symbol, as a class method, does not need to instantiate an object that can be called directly from the class itself
3. The member variable is written in {}, and the method is written outside {}, before end
4. All declared methods must be implemented
Invocation of the method
1 #import <Foundation/Foundation.h> 2 #import "Person.h" 3 4 int main (int argc, const char * argv[]) {5 @au Toreleasepool {6 person *hr = [[Person alloc]init]; 7 [hr setname:@ "HR" age:22]; 8 [HR Usetools]; 9 }10
return 0;11}
1. #import "Person.h" into the header file
2. Person *HR = [[Person alloc]init]; allocate memory and initialize space
3. [] means message, who does what
4. [HR setname:@ "Huo" age:22]; label advantages
1217.2--defines a class + method declaration call