First day learning Objective-C but have a java background. I’d like to use the same variable name for my parameter that I do for my instance variable. In java we do it like this
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;
}
}
In objective c so far I have this
@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
In Objective-C, you can define your own accessors or use
@syntehsizeto create them automatically for you.In the case where you want to define accessors manually, setters are declared like this:
For getters, you simply declare them as follows: