[英]How to declare 2D array in Objective-C?
I am new to iPhone. 我是iPhone新手。 I tried a lot to declare 2D array but I am unable to get the result.
我做了很多尝试来声明2D数组,但无法获得结果。
NSMutableArray *outerarray = [[NSMutableArray alloc] init];
outerarray = [NSMutableArray arrayWithObjects:
[NSMutableArray arrayWithObjects:@"10-20","21-30","31-40","41-50","51-60","61-70","71-80","81-90","91-100",nil,
[NSMutableArray arrayWithObjects:@"10-20","21-30","31-40","41-50","51-60","61-70","71-80","81-90","91-100",nil],
nil];
I want to combine two arrays elements and compare it with other element. 我想结合两个数组元素,并将其与其他元素进行比较。
Anyone can help me please? 有人可以帮我吗?
@"..."
is an NSString
. @"..."
是NSString
。 "..."
is not, it's a C string constant. "..."
不是,它是C字符串常量。 You need to use the @"..."
syntax for all NSString
objects you're putting into an NSArray
. 您需要对要放入
NSArray
所有NSString
对象使用@"..."
语法。
NS[Mutable]Array does not support 2D as far as I know. 据我所知,NS [Mutable] Array不支持2D。 You can probably jury-rig it to mutate and access elements in 2D (make that its own class).
您可能可以评审它来突变和访问2D中的元素(使其成为自己的类)。 Once you can access arbitrary elements, you can "combine" them and compare them as you need.
一旦可以访问任意元素,就可以“组合”它们并根据需要进行比较。 The alternative is since Objective-C is a superset of C, its
int arrayName [][]
is available (but discouraged). 另一种选择是,因为Objective-C是C的超集,所以它的
int arrayName [][]
可用(但不鼓励使用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.