I am updating some old code to our new coding standards. In this code, the int variable was incremented with the old ++ operator. Now, the int variable is a property so using ++ isn’t working so well. I’m not supposed to use dots and I’m not supposed to reference ivars directly.
Here is what I have come up with (totalHeads is the property of type int):
declaration section
@synthesize totalHeads = _totalHeads;
further down
[self setTotalHeads:[self totalHeads] + 1];
which replaces the old code of
_totalHeads ++;
Is there a more elegant way to do this?
(apologies if this is a duplicate question, I was having a hard time figuring out good search terms)
If, as you’ve mentioned in the comments, you’re not allowed to use dot syntax to access setter methods, then
[self setTotalHeads:[self totalHeads] + 1];is the only way to do it.Coding standards that disallow use of language features under all circumstances are unproductive. Maybe you can use this example to make your case.