[英]copy NSArray inside an empty NSArray
I have a first NSArray firstArray
and I do我有一个第一个 NSArray firstArray
我有
[firstArray removeAllObjects];
after I want fill it with the content of an other array secondArray
在我想用另一个数组secondArray
的内容填充它之后
is it right write in this way?这样写对吗?
firstArray = secondArray;
No, firstArray = secondArray
will reassign the pointers, this is not the behavior you want.不, firstArray = secondArray
将重新分配指针,这不是您想要的行为。 You want [firstArray addObjectsFromArray:secondArray]
你想要[firstArray addObjectsFromArray:secondArray]
Since the firstArray is an NSArray, you will want to do this instead:由于 firstArray 是一个 NSArray,因此您需要这样做:
firstArray = [NSArray arrayWithArray:secondArray];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.