第一天学习Objective-C,但有java背景。我想对参数使用与实例变量相同的变量名。在java中我们这样做
public class Person
{
private String name;
private String age;
public void setName(String name)
{
this.name = name;
}
public void setAge(String age)
{
this.age = age;
}
}
到目前为止,在目标 c 中我有这个
@interface Person : NSObject
{
int age;
int name;
}
-(void) setAge:(int) age;
-(void) setName:(int) name;
-(int) getAge;
-(int) getName;
@end
@implementation Person
-(void) setName:(int) w
{
weight = w;
}
-(void) setAge:(int) a
{
age = a;
}
-(int) getName
{
return name;
}
-(int) getAge
{
return age;
}
@end