I’ve dived into learning Objective-C and hit a little snag in when calling a method. Here’s my simple code snippets:
Player.h code snippet:
@interface Player : NSObject{
}
-(void) performAction;
-(int) addNumber:(int) a toNumber:(int) b;
@end
Player.m code snippet:
@implementation Player
-(void)performAction{
NSLog(@"Here it is!");
}
-(int)addNumber:(int)a toNumber:(int)b{
return a+b;
}
@end
Calling method from main.m:
int val = [playerOne addNumber:(int)3 toNumber:(int)3];
In the above line of code, i keep getting an ‘Expected expression’ error.
Any ideas ?
This code works for me.
Player.h
Player.m
main.m