如何在目标 C 中创建 2D NSArray 或 NSMutableArray? [英] How to create a 2D NSArray or NSMutableArray in objective C?

查看:29
本文介绍了如何在目标 C 中创建 2D NSArray 或 NSMutableArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下客观C的问题.我想在目标 C 中创建一个 2D NSArray 或 NSMutableArray.我应该怎么做?数组中存储的对象是 NSString *.非常感谢你.

I want to ask about the objective C question. I want to create a 2D NSArray or NSMutableArray in objective C. What should I do? The object stored in the array is NSString *. Thank you very mcuh.

推荐答案

这当然是可能的,但我认为值得注意的是 NSArrays 只能容纳 对象,不能容纳原始类型.

This is certainly possible, but i think it's worthy to note that NSArrays can only hold objects, not primitive types.

解决这个问题的方法是使用原始包装类型NSNumber.

The way to get around this is to use the primitive wrapper type NSNumber.

NSMutableArray *outer = [[NSMutableArray alloc] init];

NSMutableArray *inner = [[NSMutableArray alloc] init];
[inner addObject:[NSNumber numberWithInt:someInt]];
[outer addObject:inner];
[inner release];

//do something with outer here...
//clean up
[outer release];

这篇关于如何在目标 C 中创建 2D NSArray 或 NSMutableArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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