I tried to shorten my code, from :
if(i== x || i == y || i == z )
to
if (i == ( x || y || z ))
I know this way is wrong because I got incorrect i in log.
However, is there any method to shorten the code in objective-C ?
You could use a switch
statement, but that doesn't really buy you a lot with only 2-3 values.
switch (i) {
case x:
case y:
case z:
....some code....
break
default:
....some other code....
}
It'd be more of a savings if the thing you were checking was more complex or you had a lot more options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With