如何初始化 NSMutableArray
我有一个循环将值添加到 NSMutableArray
中,但是当我继续进行下一批时,我需要清除并初始化数组以添加下一批数据,我想使用 [jobList release]
可以解决这个问题,但事实并非如此。有人可以让我知道每次迭代后我可以使用什么来重置数组吗?
I have a loop which adds values to an NSMutableArray
, however when I move on to the next batch I need to clear down and initialise the array to add the next lot of data and I thought using [jobList release]
would do the trick but it doesn't. Could someone please let me know what I can use to reset the array after each iteration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您向其发送
-release
,那么该对象可能会被释放,但不确定不会被清除< /em> 如你所愿。解决方案非常简单:使用
-removeAllObjects
方法:If you send
-release
to it, then it is likely, but not certain that the object will be deallocated and not cleared as you want it to be.The solution is super-simple: Use the
-removeAllObjects
method:您可以简单地使用
[jobList removeAllObjects];
You can simply use
[jobList removeAllObjects];
如果没有其他对象保留该对象,则执行
release
可能会导致该对象被释放,因此您绝对不想这样做。要进行清除,请使用
removeAllObjects
。Doing a
release
may cause the object to be deallocated if no other objects retain it, so you definitely don't want to do that.To do a clear down use
removeAllObjects
.使用
release
将释放您正在访问的对象,这是错误的。我想你正在寻找Using
release
will deallocate the object which you are accessing, and this is wrong. I think you are looking for