NSInteger与NSInteger实现中的冲突参数类型*

时间:2014-12-26 20:03:36

标签: objective-c getter-setter nsnumber nsinteger

实施中存在“冲突的参数类型......”,如下图所示。此代码运行良好,但警告不会消失。有人可以解释这里发生了什么

Conflicting parameter type in implementation of .... NSInteger (aka long) vs NSInteger* (aka long*)

在.h文件中

@property (nonatomic) NSInteger score;
@property (nonatomic) NSInteger topScore;

在.m文件中

-(void)setScore:(NSInteger *)score
{
    _score = score;
    scoreLabel.text = [[NSNumber numberWithInteger:(long)self.score] stringValue];

}

-(void)setTopScore:(NSInteger *)topScore
{
    _topScore = topScore;
    topScoreLabel.text = [[NSNumber numberWithInteger:(long)self.topScore] stringValue];

}

1 个答案:

答案 0 :(得分:2)

这是因为NSInteger是基本类型,而不是对象。它应该通过值传递,而不是通过指针传递,即没有星号:

-(void)setScore:(NSInteger)score {
    _score = score;
    scoreLabel.text = [[NSNumber numberWithInteger:(long)self.score] stringValue];
}

同样适用于setTopScore:方法。