0

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
  • 3
    somewhere you must be re-initializing the itemsCopy array, or on each pass performing the operation on a different object.... Commented Jul 1, 2010 at 0:33
  • 1
    so addObjectsFromArray should always append? Commented Jul 1, 2010 at 1:43
  • Sheehan Alam: Yes. See the documentation: developer.apple.com/iphone/library/documentation/Cocoa/…: Nowhere does it say that it will ever reset the array, nor is there any reason why it would. Commented Jul 1, 2010 at 12:05

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.