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.
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.
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