NSMutableArray and copies
ios, nsmutablearray, objective-c, uitableview
Solution
a= [b copy]; // a is pointing to [b copy] memory location.
a= [c copy]; // a is pointing to [c copy] memory location.
You should use `setArray:` method.
[a setArray:b];
[a setArray:c];
Problem
I have 3 `NSMutableArrays`: a,b,c. ``` a= [b copy]; a= [c copy]; ``` What happens to the elements that were first copied (from b)? In my use -case, a is an array I use as DataSource for tableview, while b, an c are arrays that take the place of datasource when needed. Thanks Concrete example. In the end I got to use setArray. ``` -(IBAction)selectTab:(id)sender { if ([(UIButton*)sender tag] == 1000) { if (![self.butonLocuri isSelected]) { [tableDataSourceArray setArray:locuriArray]; [self addPins:self.tableDataSourceArray]; [self.myTableView reloadData]; } } if ([(UIButton*)sender tag] == 2000) { if(![self.butonEvenimente isSelected]){ [tableDataSourceArray setArray:evenimenteArray]; [self addPins:self.tableDataSourceArray]; [self.myTableView reloadData]; } } } ```