Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strike>You are not initializing your array (on line 1) and are pointing to unused memory. It should be</p> <pre><code>NSMutableArray *numbersArray = [[NSMutableArray alloc] init]; </code></pre> <hr> <p>What you are doing is different from pointing to <code>nil</code> which is safe. If you would have done</p> <pre><code>NSMutableArray *numbersArray = nil; </code></pre> <p>you would have seen that the array was always empty because it was sending a message to <code>nil</code> causes nothing to happen (e.g. adding objects to <code>nil</code> don't do anything at all).</strike></p> <hr> <h2>Update (after your edit):</h2> <p>Your code runs fine. You are probably just not getting what it does. </p> <p>Your first few lines create an array with 34 values that are all <code>-1</code></p> <pre><code>NSMutableArray *numbersArray = [[NSMutableArray alloc] init]; for (int i = 0; i&lt;34; i++) { numbersArray[i] = [NSNumber numberWithInt:-1]; } </code></pre> <p>You then randomize one integrer value between 0 and 33</p> <pre><code>int r = rand()%34; </code></pre> <p>And then "while" the array of all -1's contain that number you randomize a new number. </p> <p>Since your first number is positive and the array is filled with all -1's you never enter the body of the loop so your code just steps over it.</p> <pre><code>while ([numbersArray containsObject:[NSNumber numberWithInt:r]]) { //it breaks here r = rand()%34; } </code></pre> <p><strong>I can't really understand what you are trying to do but this is what your code is currently doing. (It works but is quite pointless)</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload