Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The capacity is merely how many objects a container class can hold. Inserting at an index requires that index to be a valid placement for the new object based on the total number of objects contained in the container (not the total number of objects that CAN be contained).</p> <p>If your array's values are index dependent (which is seems like perhaps a different architecture or data structure would be better) then you can ensure that every index is filled by prepopulating the array with NSNulls. This would require you to check for NSNulls when reading from the array later on though which would likely be extra work, hence why this is probably not the best approach. In any case, you can change your code to the following to fix your crash.</p> <pre><code>factsBuiltArray = [NSMutableArray arrayWithCapacity: 6]; for (NSUInter i = 0; i &lt; 6; i++) { [factsBuiltArray addObject:[NSNull null]]; } if ([statusDict count] == 10) { for (NSString *key in [statusDict allKeys]) { if ([key isEqualToString: @"currenciesAndConversions"]) { [factsBuiltArray replaceObjectAtIndex:0 withObject:key]; } else if ([key isEqualToString: @"languageAndTranslations"]) { [factsBuiltArray replaceObjectAtIndex:1 withObject:key]; } else if ([key isEqualToString: @"plugSize"]) { [factsBuiltArray replaceObjectAtIndex:2 withObject:key]; } else if ([key isEqualToString: @"timezone"]) { [factsBuiltArray replaceObjectAtIndex:3 withObject:key]; } else if ([key isEqualToString: @"population"]) { [factsBuiltArray replaceObjectAtIndex:4 withObject:key]; } else if ([key isEqualToString: @"wikipedia"]) { [factsBuiltArray replaceObjectAtIndex:5 withObject:key]; } } } </code></pre>
 

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