Instead of overloading these float
properties (call them X and Y), create a separate isValid
flag for each property. Initialize the flags to indicate that the floats have not been set, and to provide their own setters with the proper control of the flags. So your code might look something like this:
if (self.isXValid == YES) { self.Y = ...
In fact, you can take another step, and the setter for X also assign Y and vice versa. Or, if X and Y are so closely related that you can calculate them based on the value of another, you really only need one variable for both properties.
source share