In my iPhone app.
I am copying the one mutable array(with dictionary) to another.
It is like
resultsToDisplay = [[[NSMutableArray alloc]initWithArray:resultsPassed]mutableCopy];
2012-06-21 17:07:07.441 AllinoneCalc[3344:f803] Results To Display (
{
lbl = "Monthly EMI";
result = "75.51";
}
)
2012-06-21 17:07:08.224 AllinoneCalc[3344:f803] Results Passed (
{
lbl = "Monthly EMI";
result = "75.51";
}
)
Then I am modifying one of them .
[[resultsToDisplay objectAtIndex:i] setValue:[NSString stringWithFormat:@"%.2f",[[[resultsPassed objectAtIndex:i] valueForKey:@"result"] floatValue]] forKey:@"result"];
But what is happening that both are getting edited.
2012-06-21 17:07:08.703 AllinoneCalc[3344:f803] Results Passed (
{
lbl = "Monthly EMI";
result = "75.00";
}
)
2012-06-21 17:07:08.705 AllinoneCalc[3344:f803] Results To Display (
{
lbl = "Monthly EMI";
result = "75.00";
}
)
They both are referring to the same copy.
How to solve this. I want to modify only one array.
You are only copying the array of object pointers, not the object themself. See this article on deep copying.