Maybe I'm doing something obviously wrong here, but why does this code behave like this:
NSMutableArray<NSNumber*> *a = @[@(0), @(0), @(0)].mutableCopy;
a[3] = @(1); // works, but why?
a[4] = @(1); // also works
NSMutableArray<NSNumber*> *b = @[@(0), @(0), @(0)].mutableCopy;
b[4] = @(1); // crash 💥 index 4 beyond bounds [0 .. 2]
The documentation says that:
If index is beyond the end of the array (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.
https://developer.apple.com/documentation/foundation/nsmutablearray/1460093-setobject