Incompatible integer to pointer conversion assigning to 'int *' from 'int'

56,099

Solution 1

There's a big hint in the error message!

In C and Objective C, an int is a primitive data type. You've written int *, which means "a pointer to an int", whereas it looks like you just wanted an int.

So change your property to this:

@property (nonatomic, assign) int myInt;

For more info, google "C pointers" and you'll find information like this: http://pw1.netcom.com/~tjensen/ptr/pointers.htm

Solution 2

Yes, simply remove asterisk (*) from declaration.

for example.declare BOOL isChecked instead of BOOL * isChecked.

Solution 3

Another way to resolve this is to simply not declare a pointer (drop the asterisk):

@interface ViewController : UIViewController {
    NSUInteger myObjcInt;  // unsigned ( >= 0 ) NSObject int, yo
}

Solution 4

int *MyInt is a pointer to int, not an int.
As others told you, just remove the * and you will have a regular int.

Share:
56,099

Related videos on Youtube

Preston
Author by

Preston

Updated on July 09, 2022

Comments

  • Preston
    Preston almost 2 years

    I have yet another pesky warning I would like gone. Basically, I have an int declared like this: @property (nonatomic, assign) int *myInt; and set like this: myInt = 0;. It is also synthesized in the implementation file. I am getting a warning on the line where I set the int's value and it says Incompatible intiger to pointer conversion assigning to 'int *' from 'int'. What should I do to fix this?

  • Chuck
    Chuck over 12 years
    That's not another way — it's the same thing occulus said. BTW, your comment calls it an "NSObject int", which doesn't really make a lot of sense as a term.
  • Rob
    Rob over 12 years
    Touche. I was reading this post during a search for an NSInteger-related issue, not Int. A little too quick on the reply there, guys. My bad.