Objective-C方法调用中的表达式错误

Objective-C方法调用中的表达式错误,objective-c,nsobject,Objective C,Nsobject,我已经开始学习Objective-C,在调用方法时遇到了一个小障碍。以下是我的简单代码片段: Player.h代码片段: @interface Player : NSObject{ } -(void) performAction; -(int) addNumber:(int) a toNumber:(int) b; @end @implementation Player -(void)performAction{ NSLog(@"Here it is!"); } -(int

我已经开始学习Objective-C,在调用方法时遇到了一个小障碍。以下是我的简单代码片段:

Player.h代码片段:

@interface Player : NSObject{


}

-(void) performAction;
-(int) addNumber:(int) a toNumber:(int) b;

@end
@implementation Player

-(void)performAction{
    NSLog(@"Here it is!");
}

-(int)addNumber:(int)a toNumber:(int)b{
    return a+b;

}


@end
Player.m代码片段:

@interface Player : NSObject{


}

-(void) performAction;
-(int) addNumber:(int) a toNumber:(int) b;

@end
@implementation Player

-(void)performAction{
    NSLog(@"Here it is!");
}

-(int)addNumber:(int)a toNumber:(int)b{
    return a+b;

}


@end
从main.m调用方法:

int val = [playerOne addNumber:(int)3 toNumber:(int)3];
在上面的代码行中,我不断得到一个“Expected expression”错误


有什么想法吗?

这段代码适合我

Player.h

#import <Foundation/Foundation.h>

@interface Player : NSObject

- (void)performAction;
- (int)addNumber:(int)a toNumber:(int)b;

@end
main.m

#import "Player.h"

@implementation Player

- (void)performAction {
    NSLog(@"Here it is!");
}

- (int)addNumber:(int)a toNumber:(int)b {
    return a+b;
}

@end
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Player.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        Player *playerOne = [Player new];
        int val = [playerOne addNumber:(int)3 toNumber:(int)3];

        NSLog(@"%d", val);


        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
#导入
#导入“AppDelegate.h”
#导入“Player.h”
int main(int argc,char*argv[])
{
@自动释放池{
Player*playerOne=[Player new];
int val=[playeron addNumber:(int)3 tonnumber:(int)3];
NSLog(@“%d”,val);
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([AppDelegate类]);
}
}

注释已删除:无法挽救。@失败的计算机科学家请提供您的主要功能。我敢肯定,一定有语法错误。也许是因为看不见的角色。你复制并粘贴了它吗?你可以尝试删除行开头的所有空格
int val=[playerne addNumber:(int)3 tonnumber:(int)3]到前面的行末尾。@vikingosegundo:将尝试此操作。但是,我发现在调用方法时没有必要包含该类型。我忘了脱模。它们是完全没有必要的。这很有趣。它只在我移除整型后对我有效。