//创建对象( alloc在堆内存开辟空间)并且给person对象进行初始化
main.m
Person *person = [[Person alloc]init]];
person->name = @"文强";
person->age = 12;
person->gender = @"男";
Person.h
{
NSString *_name;
NSInteger _age;
NSString *_gender;
}
- (void)sayHi;
- (void)eat;
- (void)setName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender;
Person.m
- (void)sayHi{
NSLog(@"我是%@,我今年%ld,我的性别是%@",_name,_age,_gender);
}
- (void)eat {
NSLog(@"吃");
}
- (void)setName:(NSString *)name age:(NSInteger)age gender:(NSString *)gender{
_name = name;
_age = age;
_gender = gender;
[self sayhi];
}