views:

41

answers:

1

I have the following code (both items and itemsCopy are NSMutableArray's):

//DO: populate items w/ 30 elements
[self.itemsCopy addObjectsFromArray:self.items];
//DO: remove all elements in items

Results

Begin Pass 1:
itemsCopy = 0
items = 30

End Pass 1:
itemsCopy = 30
items = 0

Begin Pass 2:
itemsCopy = 0
items = 30

End Pass 2:
itemsCopy = 30
items = 0

How can I constantly append items to the end of itemsCopy? I would like the scenario to look like this:

Begin Pass 1:
itemsCopy = 0
items = 30

End Pass 1:
itemsCopy = 30;
items = 0;

Begin Pass 2:
itemsCopy = 30
items = 30

End Pass 2:
itemsCopy = 60
items = 0
+3  A: 

By keeping the same array you just filled in the itemsCopy property. It's clearly being reset to an empty array with whatever method you're using.

Chuck