-3

For some reason, when I try to increment one of my integers, it increments by four instead of one! The only thing I can think of is something wrong in the .h file. The integer is declared like this:

@property (nonatomic, assign) int *number;

and in the code I increment it by doing self.number++;. I already checked and the method only runs once before it shows on the screen, and when I NLogged directly around it, it shows it incrementing by 4. To make matters worse, I tried changing it to NSInteger for hahas and it incremented by 8!

jscs
  • 63,095
  • 13
  • 148
  • 192
Kiley
  • 409
  • 1
  • 4
  • 16
  • the * is denoting that your property is a pointer, so when you increment you are incrementing by the data size to the next address. @Sulthan has the answer below. – jrisberg Aug 03 '15 at 17:46

1 Answers1

4

Remove * from the property definition.

When you have int, ++ is integer increment. However, when you have an int* you have a pointer and ++ is pointer increment, moving the pointer by the size of an int (sizeof(int)).

Sulthan
  • 123,697
  • 21
  • 207
  • 260