I have a first NSArray firstArray
and I do
[firstArray removeAllObjects];
after I want fill it with the content of an other array secondArray
is it right write in this way?
firstArray = secondArray;
No, firstArray = secondArray
will reassign the pointers, this is not the behavior you want. You want [firstArray addObjectsFromArray:secondArray]
Since the firstArray is an NSArray, you will want to do this instead:
firstArray = [NSArray arrayWithArray:secondArray];
来源:https://stackoverflow.com/questions/6344563/copy-nsarray-inside-an-empty-nsarray