添加整数的NSMutableArray [英] Adding Integer To NSMutableArray

查看:391
本文介绍了添加整数的NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何地方这样,所以我要求只是要求,以确保。是的,我知道它的基本的,但我想我宁愿得到权利之前,我犯错误了一百万次:

如果我这样做,不是在默认情况下投出0,以一个NSNumber(如果没有,什么对象类型的话),或者我会做第二次code?

(或两种可能是错误的,我想要做的事。如果是这样,让我知道,他们都编译,所以我只是想知道哪一个是正确的(或preferred),为什么。)

code 1:

 的NSMutableArray数组= [[[NSMutableArray里的alloc]初始化]自动释放];
[阵列ADDOBJECT:0];

code 2:

 的NSMutableArray数组= [[[NSMutableArray里的alloc]初始化]自动释放];
[阵列ADDOBJECT:[NSNumber的numberWithInt:0]];


解决方案

的NSMutableArray 不采取原始类型的。


  

第二个选项是正确的。


I couldn't find this anywhere, so I am asking just asking to make sure. And yes, I know its basic, but I figure I'd rather get that right before I make the mistake a million times:

If I do the following, does it cast the "0" to an NSNumber by default (if not, what Object type is it), or would I have to do the 2nd code?

(Or both of these could be wrong for what I'm trying to do. If so, let me know. They both compile so I am just wondering which one is "right" (or preferred) and why.)

Code 1:

NSMutableArray array = [[[NSMutableArray alloc] init] autorelease];
[array addObject: 0];

Code 2:

NSMutableArray array = [[[NSMutableArray alloc] init] autorelease];
[array addObject: [NSNumber numberWithInt: 0]];

解决方案

NSMutableArray doesn't take primitive types.

The second option is correct.

这篇关于添加整数的NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆