views:

123

answers:

1

How can you increment a integer property?

You can't do self.integer++, you can do integer++, but I'm not sure wether or not that will retain it..

Will the last one retain the value of "integer"?

Thanks.

+1  A: 

integer++ works because you are accessing the integer directly and assigning a new value to integer instead of sending a message and using accessors. Assuming that integer is declared as an NSInteger property the following statements are will have the same effect on the value of integer, however direct access is not KVO compliant.

[self setInteger:0];
self.integer = self.integer + 1; // use generated accessors
NSLog(@"Integer is :%d",[self integer]); // Integer is: 1
integer++;
NSLog(@"Integer is :%d",[self integer]); // Integer is: 2
falconcreek
Ok, thanks :) [blahblahblah, trying to fill this comment up, stupid char-limit.]
Emil