Consecutive Number After 16 in iOS

4 Solutions Collect From Internet About “Consecutive Number After 16 in iOS”

This can be reduced to a mathematical problem. What you want is to divide by 16 and see if there is no ‘remainder’. The ‘modulo’ operator gives you this remainder. You can Google it if you want to understand. So, as others have quickly posted before me, modulo in Objective-C is done via %. So x % 16 means: divide x by 16 and return the remainder (or: subtract 16 from x until x is smaller than 16). x % 16 will be a number between 0 and 15. Always. When x % 16 is 0, it means x is dividable by 16.

Since you want to take action when count is 2 + 16 * n, you want to subtract 2 from count first. Like so if ( ( count - 2 ) % 16 == 0). Or you can do this, which is shorter but perhaps less easy to understand: if ( count % 16 == 2 ).

Take the current count and subtract 2. If the number is divisible by 16 (the remainder when you do modulo division is zero), then your statement is true.

if ((count - 2) % 16 == 0)
{
    _secondBall.hidden = YES;   
}

Try this:

if ((count - 2) % 16 == 0)

Use this syntax

if ((count-2) % 16 == 0)