Search code examples
objective-cgetter-setternsnumbernsinteger

Conflicting parameter type in implementation of NSInteger vs NSInteger*


There are 'conflicting parameter type in implementation...', as you can see in the image below. This code is working well, but the warning won't go away. Can someone explain what's going on here

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

In the .h file

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

In the .m file

-(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];

}

Solution

  • This is because NSInteger is a primitive type, not an object. It should be passed by value, not by pointer, i.e. without an asterisk:

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

    Same goes for setTopScore: method.