I just began a series of tutorials in Objective C as my first serious programming language to learn (I have a very basic and fragmented knowledge of Android). I am following a series of tutorial videos and have come across code sprinkled with errors. The author of the tutorials uses the same code flawlessly. I am new to Objective C, so I am having trouble figuring out what is wrong with my code. Here it is:
#import <Foundation/Foundation.h>
//-----interface-----
@interface Person: NSObject{
int age;
int weight;
}
-{void} print;
-{void} setAge: {int} a;
-{void} setWeight: {int} w;
@end
//-------implementation-------
@implementation Person
-{void} print{
NSLog(@"I am %i years old and weigh %i pounds", age, weight);
}
-{void} setAge: {int} a{
age=a;
}
-{void} setWeight: {int} w{
weight=w;
}
@end
int main{int argc, char *argV[]}{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
Person *amrit;
amrit = [Person alloc];
amrit = [amrit init];
[amrit setAge: 16];
[amrit setWeight: 125];
[amrit print];
[amrit release];
[pool drain];
return 0;
}
Return type and argument type should be enclosed in
()and not in{}. The same when you are doing the implementation too.