0

I have made multidemensional arrays in c++ but I am confused on how to do this in objective c because it is a modified version of c. How would I go about making a multidimensional array in Objective C?

4

1 回答 1

2
NSArray *twoDArray = @[@[@"0.0", @"0.1"], 
                       @[@"1.0", @"1.1", @"1.2"], 
                       @[@"2.0", @"2.1", @"2.2"]
                     ];

像这样访问它:

// result = "0.1"
NSString *result = twoDArray[0][1];

// result = "1.2"
result = twoDArray[1][2];

// result = "2.0"
result = twoDArray[2][0];

尽管(根据评论)它们的功能确实完全不同,但您在使用它们时与在 C 中的使用并没有太大的不同。Objective-C 也不是 C 的真正修改版本。它是 C 的一切,还有更多。所以它实际上并没有修改任何关于 C 的内容。

这种语法(用于创建和访问数组值)也相对较新,有关更多信息,您可以查看文档此答案,它们都概述了 Objective-C 文字的一些其他特性。

于 2013-10-27T01:04:41.817 回答