-2

Implicit conversion of 'NSInteger' (aka 'int') to 'UILabel *' is disallowed with ARC Ok so this is what I am trying to do- I am following a tutorial on youtube and I have a label on ViewController on Xcode's storyboard and am trying to keep a "high score" on the first screen (view controller) using a label and .text (see below):

  HighScore =[[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"];
    HighScore.text = [NSString stringWithFormat:@"High Score: %li", (long)HighScore];

I did declare NSInteger = HighScore in my .h file and it is included but I still get the "Implicit conversion" error report. Any Clues what's going on?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
PICKme
  • 39
  • 5
  • High score is an integer right? An integer doesn't have a text property. That second line needs to have the name of your label property.text not HighScore.text – rdelmar Jul 28 '14 at 01:00
  • can you give an example? – PICKme Jul 28 '14 at 01:12
  • @rdelmar Based on the message: "Implicit conversion of 'NSInteger' (aka 'int') to 'UILabel *'" this means that `HighScore` is a `UILabel` since the message means that the code is trying to assign an `NSInteger` (from the `integerForKey:` call) to a `UILabel *` (`HighScore`) in the 1st line of the posted code. – rmaddy Jul 28 '14 at 01:17
  • http://www.youtube.com/watch?v=GWcEwErcMxs – PICKme Jul 28 '14 at 01:18
  • OMy gosh my bad guys I named the UILabel and NSInt the same thing on accident so i suppose you were both right – PICKme Jul 28 '14 at 01:21
  • @rmaddy, thanks, I guess I didn't read that error message close enough. – rdelmar Jul 28 '14 at 01:31

1 Answers1

0

It seems that your HighScore variable is a UILabel. You can't assign the value from NSUserDefaults to the label.

Try this:

NSInteger score = [[NSUserDefaults standardUserDefaults] integerForKey:@"HighScoreSaved"];
HighScore.text = [NSString stringWithFormat:@"High Score: %li", (long)score];

BTW - consider using standard naming conventions. Variable and method names should begin with lowercase letters. Class names begin with Uppercase letters.

rmaddy
  • 314,917
  • 42
  • 532
  • 579