0

In my view controller I call with a reference to game, which is an istance of Game class

score.text = [NSString stringWithFormat:@"%d", [game score]];

Game has this:

int score
@property (nonatomic, readwrite) int *score ;

son normally score has a getter. Game.h is included in ViewController.h

Why do I get "unrecognized selector sent to instance"?

Michele
  • 681
  • 3
  • 16
  • 27
  • what does the error say specifically? i suspect you have released game or not assigned it correctly. Edit: see my answer as well. – Jesse Naugher Jun 13 '11 at 15:38
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:52

3 Answers3

1

Did you synthesize it in your implementation?

@synthesize score;

Also, you do not want a pointer to an int, but an int itself. Remove the '*'.

Thirdly, I'm assuming score.text is setting the text for a UILabel or similar? And is different from Game's score.

Another check you can use is to make use of dot-notation. If the property is not properly set, you will get an error rather than a warning. I.e. game.score instead of [game score].

MarkPowell
  • 16,482
  • 7
  • 61
  • 77
  • Yes, all is done and as you suggested I modified the label's name which was the same as the score proprety. now it is scoreLabel. But I got the same problem – Michele Jun 13 '11 at 15:47
1

score.text = [NSString stringWithFormat:@"%d", [game score]];//u can use %i instead %d

int score

@property (nonatomic, readwrite) int score ;//remove here ur star

or

@property (nonatomic) int score ;//remove here ur star

0

Not sure, if thats a typo, but the property declaration of score doesn't need an asterisk, as its a primitive type, so that could definitely be the issue.

Jesse Naugher
  • 9,780
  • 1
  • 41
  • 56