Has*_*y31 0 iphone cocoa objective-c ios
我有五个整数.我将所有整数添加到mutableArray并将其洗牌.
int A = 1;
int B = 2;
int C = 3;
int D = 4;
int E = 5;
myArray = [2,1,3,5,4]; //shuffled array
Run Code Online (Sandbox Code Playgroud)
是否有可能获得数组中每个整数的变量名?请帮我.
在这种情况下,NSDictionary是可行的,您可以存储变量名称及其值:
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"1",@"A",@"2",@"B",@"3",@"C",@"4",@"D",@"5",@"E", nil];
Run Code Online (Sandbox Code Playgroud)
现在您可以获取字典的所有键,如:
NSArray *arr = [dict allKeys]; // which will be [A,B,C,D,E]
Run Code Online (Sandbox Code Playgroud)
您可以获取这些键的值,如:
for (int i=0; i<arr.count; i++) {
NSLog(@"%@",[dict valueForKey:[arr objectAtIndex:i]]); // Will print 1,2,3,4,5
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
859 次 |
| 最近记录: |