cyclingIsBetter
cyclingIsBetter

Reputation: 17591

copy NSArray inside an empty NSArray

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; 

Upvotes: 0

Views: 721

Answers (2)

BP.
BP.

Reputation: 10083

Since the firstArray is an NSArray, you will want to do this instead:

firstArray = [NSArray arrayWithArray:secondArray];

Upvotes: 1

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

No, firstArray = secondArray will reassign the pointers, this is not the behavior you want. You want [firstArray addObjectsFromArray:secondArray]

Upvotes: 1

Related Questions