Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace object Index in NSMutableArray

I have NSMutableArray. There are for example such objects: 0, 1, 2. How can I replace object 0 into index where object 2. In result I want array with objects: 1, 2, 0. Thanks.

like image 845
LightNight Avatar asked Feb 23 '23 08:02

LightNight


1 Answers

@trojanfoe, there is a simple mistake in your answer.

The first line of the code does not return anything as per doc. So it should be,

id object = [[array objectAtIndex:0] retain];
[array removeObjectAtIndex:0];
[array insertObject:object atIndex:2];
[object release];
like image 145
Ilanchezhian Avatar answered Mar 03 '23 20:03

Ilanchezhian