好的,我有一些看起来像这样的 C# 代码,我想知道如果我试图将其放入 Objective-C 中,其他开发人员会推荐什么。
List<List<string>> meta_data
我正计划使用NSMutableArray,但如何准确地计算出二维数组是我的问题,因为在 Objective-C 中没有多维数组这样的东西。我是新手NSMutableArray,所以我仍然不时需要一些帮助。
我知道一旦我弄清楚了整个“二维”部分,我就会使用 NSString 将字符串对象添加到数组中。
好的,我有一些看起来像这样的 C# 代码,我想知道如果我试图将其放入 Objective-C 中,其他开发人员会推荐什么。
List<List<string>> meta_data
我正计划使用NSMutableArray,但如何准确地计算出二维数组是我的问题,因为在 Objective-C 中没有多维数组这样的东西。我是新手NSMutableArray,所以我仍然不时需要一些帮助。
我知道一旦我弄清楚了整个“二维”部分,我就会使用 NSString 将字符串对象添加到数组中。
数组可以容纳任何对象。我不熟悉 C# 代码,但我想你所做的所有事情都是嵌套数组。
您需要使用的是 objectAtIndex: 用于 NSArrays。
NSString *hello = @"Hello World";
NSMutableArray *insideArray = [[NSMutableArray alloc] initWithObjects:hello,nil];
NSMutableArray *outsideArray = [[NSMutableArray alloc] init];
[outsideArray addObject:insideArray];
// Then access it by:
NSString *retrieveString = [[outsideArray objectAtIndex:0] objectAtIndex:0];
我认为您正在寻找类似的东西。这有帮助吗?
像这样的东西:
//Create the array of strings
NSMutableArray *strings = [[NSMutableArray alloc] init];
[strings addObject:@"someString"];
[strings addObject:@"someOtherString"];
//Create the array to hold the string array
NSMutableArray *container = [[NSMutableArray alloc] init];
[container addObject:strings];
您将使用包含 NSStrings 的 NSMutableArrays 的 NSMutableArray