[array objectAtIndex:i] doesn't work as an L value, so it can't be used to set the object at index i.
[array objectAtIndex:i]
Use -insertObject:atIndex: or replaceObjectAtIndex:withObject:.
-insertObject:atIndex:
replaceObjectAtIndex:withObject: