How to swap values in NSMutableArray?
Posted
by Harry Pham
on Stack Overflow
See other posts from Stack Overflow
or by Harry Pham
Published on 2010-04-07T04:38:47Z
Indexed on
2010/04/07
4:43 UTC
Read the original article
Hit count: 292
This piece of codes segment fault on me, any idea why? allButtons
is a NSMutableArray
, it contains 3 objects, a=0, b=1
, a and b are int
type
if(a != -1 && b!= -1){
//Swap index in "allButtons"
id tempA = [allButtons objectAtIndex:a];
id tempB = [allButtons objectAtIndex:b];
[allButtons replaceObjectAtIndex:a withObject:tempB]; //Seg fault here?????
[allButtons replaceObjectAtIndex:b withObject:tempA];
needLoad = false;
[self setUpButtons];
}
© Stack Overflow or respective owner