1, Code Description:
Person.h
Person.h
#import
@interface Person:nsobject
{
Definition of int age,sex;//variable
int height,width;
}
Definition of the @property int age,sex;//property
@property char height;
-(void) setage;
-(int) SetAge1:(int) A;
-(int) Setwh:(int) w:(int) h;
/* Definition of method
Format
-(returned data type) method name:(parameter 1 data type) Parameter 1 is called:(Parameter 2 data type) parameter 2 is called
*/
@end
Person.m
Person.m
#import "Person.h"
@implementation person
@synthesize age,sex;//Accessor
@synthesize height;
/*
"My notes."
@synthesize Reference @property Association @interface
References that are not, or are not associated with, are thrown incorrectly.
*/
#pragma mark------setage----
-(void) setage;
//{
age=20;
//}
#pragma mark------setAge1------
-(int) SetAge1:(int) A
{
Age=a;
return age;
}
#pragma mark------SETWH------
-(int) Setwh:(int) w:(int) H//method implementation
{
width = 100;
height=175;
return age*height;
}
@end
Main.m
Main.m
#import
#import "Person.h"
int main (int argc, const char * argv[])
{
@autoreleasepool {
Person *person=[person alloc];
[Person Init];
person.age=1;//Property
NSLog (@ "Person.ag =%i", person.age)//Output property, note type match, or throw wrong
NSLog (@ ' person =%@ ', person);/Output Object
[Person Setwh:6:10];//method
[Person release];//if the arc mechanism is used, release is not available.
}
return 0;
}
2, my comments (see below three pictures):
@synthesize Reference @property Association @interface
References that are not, or are not associated with, are thrown incorrectly.