obj-c中C ++的新增和删除命令 [英] New and delete command of c++ in obj-c
本文介绍了obj-c中C ++的新增和删除命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象的NSMutablearray.对象的数量由用户设置.在c ++中,我将使用for循环和'new'命令.类似这样:
I have an NSMutablearray of objects. the number of objects is set by user. in c++ I would use a for cycle and the 'new' command.something like this:
int fromuser, a;
for(a=0;a<fromuser;a++){
array addobject:(new class obj)
}
由于没有新内容,我需要在obj c中做什么?
what do I need to do in obj c since there is no new?
推荐答案
您将使用例如,类似以下的内容应该起作用:
For example, something like the following should work:
int fromuser, a;
NSMutableArray objectArray = [[NSMutableArray alloc] initWithCapacity:fromuser];
for (a = 0; a < fromuser; a++)
{
MyObject *obj = [[MyObject alloc] init];
[objectArray addObject:obj];
[obj release]; //If not using ARC
}
这篇关于obj-c中C ++的新增和删除命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文