开发者

copy NSArray inside an empty NSArray

开发者 https://www.devze.com 2023-03-12 15:19 出处:网络
I have a first NSArray firstArray and I do [firstArray remo开发者_C百科veAllObjects]; after I want fill it with the content of an other array secondArray

I have a first NSArray firstArray and I do

[firstArray remo开发者_C百科veAllObjects];

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号