copy NSArray inside an empty NSArray

后端 未结 2 905
执念已碎
执念已碎 2021-01-16 18:45

I have a first NSArray firstArray and I do

[firstArray removeAllObjects];

after I want fill it with the content of an other a

相关标签:
2条回答
  • 2021-01-16 18:53

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

    0 讨论(0)
  • 2021-01-16 18:59

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

    firstArray = [NSArray arrayWithArray:secondArray];
    
    0 讨论(0)
提交回复
热议问题