Add an object to the beginning of an NSMutableArray? Add an object to the beginning of an NSMutableArray? ios ios

Add an object to the beginning of an NSMutableArray?


As other answers have noted just use the insertObject:atIndex method. It is efficient as NSArrays do not necessarily consist of contiguous memory i.e. the elements don't always get moved when the insert happens especially for large arrays i.e. several hundred of thousand elements. See this blog Also note that in objective C only pointers are moved in the array so memmove can be used internally unlike C++ where copies have to be made.

Also this SE question.