Type or property (NSUInteger (aka unsigned int)) does not match type of ivar (int)

StackOverflow https://stackoverflow.com/questions/12098302

  •  28-06-2021
  •  | 
  •  

Domanda

I want to declare a NSInteger variable in my ViewController, but I get an error.

In my ViewController.h I have

@interface MainViewController : UIViewController{
    NSInteger currentSection;
    //Other stuff  
  }

  @property (assign,nonatomic) NSUInteger currentSection;
@end

and in my ViewController.m I have:

@implementation MainViewController

//Other stuff
@synthesize currentSection;

But I get this error:

Type of property 'currentSection' ('NSUinteger' (aka 'unsigned int')) does not match type of ivar 'currentSection' ('int')

Why do I get this error with one simple instruction?
I'm using Xcode 4.4 with ARC.

È stato utile?

Soluzione

You are asking the compiler to synthesize a NSUInteger property with a NSInteger ivar. You have to decide what the type of the property should be and adapt the type of the ivar accordingly.

Note that unsigned integer are not equivalent to (implicitly signed) integer. Casting one to the other might give you unexpected results.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top