i have one array this array contain Question Objects so here i need to change the positions for array
Question *que=[[Question alloc]init];
que=[myarray objectAtIndex:1];
Question *que1=[[Question alloc]init];
que1=[myarray objectAtIndex:2];
here i need to inter change objects each other some
[que1 setValue: que.name forKey:@"Name"];
[myarray relplaceObjectAtIndex:2 withObject:que1];
is it right way to set value same objectValues
Please guide me hoe can inter change value.
Thanks for advance
There are significant issues with your code here:
This statement:
Allocates a new
Questioninstance and assigns it to the variableque. When you do:You are overwriting the
Questioninstance that you just allocated, effectively leaking memory (because you never released it). This won’t be a problem if you are using ARC but nevertheless it is something to be mindful of because with or without ARC it is pointless. You did this twice, once forqueand once forque1. Since you don’t actually need to allocate and initialise a newQuestioninstance, you can just do:You obtain a reference to a
Questionobject and assign it toque1. Then you mutate it and want to put it back into the array. This is pointless because the array already holds a reference to the sameQuestioninstance that you obtained withobjectAtIndex:.You haven’t really explained what you are trying to do. Your entire code basically boils down to: