1、对象作为方法的参数
假设有Person类: Person类有name、sex属性
假设实例化Person的对象
Person *p = [Person new];
p->name ="凤姐";
p->sex = "女";
...... ......
-(void) displayPerson:(Person *)person{
NSLog("姓名:%@",person->name); NSLog("姓名:%@",person->sex);
} ...... ......
2、对象做方法的返回值
-(Person *)changePerson:(Person *)person{
person->name = @"唐僧";
person->sex =@"男";
person->age = person->age+1;
return person;
}
Person *p2 = [d changePerson:p1];
[d displayPerson:p2]; |
|