0

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

}
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
Vins Rach
  • 41
  • 9

1 Answers1

3

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.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • 1
    To be more specific/accurate NSInteger* is a POINTER to an NSInteger; i.e. a memory address. You can pass around pointers to primitives, but you have not declared your property as such. – Jef Dec 26 '14 at 20:44
  • In case of non-primitive types, NSString and NSString* are different types (although NSString is often not a legal type), and NSString* and NSString** are different types. – gnasher729 Dec 26 '14 at 21:00