objective-c - 简单数组的问题 - Cocoa

标签 objective-c arrays cocoa syntax-error

我想知道是否有可能执行以下操作:

我有一个方法,例如:

one = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3", nil];
two  = [[NSMutableArray alloc] initWithObjects:@"4",@"5",@"6", nil];

-(void)getStringAndChooseArray:(NSString *)nameOfArray {
//What i want to do is something like:
NSLog(@"The array %@ has got %i objects",nameOfArray,[nameOfArray count]) 
//Of course it is giving me an error since nameOfArray is a string..

//I know it is hard to understand,
//but what I'm trying to do is to call this method
//pass a string variable, which is named as one of the two arrays,
//and using it to do the rest..

}

如何使用字符串来识别数组并对其进行操作?

提前致谢!

最佳答案

将数组存储在字典中,并使用您想要引用它们的名称作为其相关键。

关于objective-c - 简单数组的问题 - Cocoa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13805512/

相关文章:

iPhone - 将 UISwitch 上的文本从 "ON/OFF"更改为 "TRUE/FALSE"?

ios - 从不同的目标获取 Bundle ID

java - 如何反序列化来自 RESTful Web 服务的 JSON 响应?

mysql - 如何从单个数组中的两个查询传递json

c - 缓冲文件中的一组行并将其存储在 C 中的数组中

cocoa - 如何制作扁平化的NSButton?

ios - 通过 swift 集成新的 facebook SDK

java - CompareTo() 字符串/合并排序

Cocoa 数据层次结构和浏览器

cocoa - 在 MAC OSx 上将 FLV 转换为 MP4 视频文件