I have the following function:
+ (int)isCorrectOnServer:(int)num {
// some code performs here...
if (this)
{
result = 2;
}
else if (this2)
{
result = 1;
}
else
{
result = 0;
}
return result; }
I want it to return like this instead:
+ (int)isCorrectOnServer:(int)num {
// some code performs here...
if (this)
{
result = kOnServer;
}
else if (this2)
{
result = kWrongType;
}
else
{
result = kNotOnServer;
}
return result; }
So anywhere in my code I could just call:
if ([Helper isCorrectOnServer:276872] == kOnServer)
to make my code cleaner and not show 0, 1, or 2 as the result. What is the best way to go about doing this?
When in doubt, see what Apple do. Look in any header file in UIKit and you will see enumeration being used for any kind of value with a finite amount of options.
Just put this in the header file:
Using proper enumerations over defines allow you to do define a method like this:
Then the argument can be auto completed for you by Xcode. And the compiler can make much better assumptions if you use the value in a switch case for example.