NSMutableArray *output = [[NSMutableArray alloc]init];
要么
NSArray *output = [[NSMutableArray alloc]init];
我可以设置键和值。现在,我只想访问每个键和值,但是我不知道设置的键数。
在PHP中非常简单,如下所示:
foreach ($output as $key => $value)
在Objective-C中怎么可能?
最佳答案
我认为您对NSArray的NSDictionary感到困惑。
在NSDictionary中,您可以使用以下键设置对象
NSMutableDictionary *output = [[NSMutableDictionary alloc]init];
[yourDictionary setObject:@"yourvalue" forKey:@"yourKey"];
你可以得到像
[yourDictionary objectForKey:@"yourKey"];
在您的数组中,它只是将对象添加到索引中。
NSArray * output = [[NSArray alloc] initWithObjects:@"option1",@"option2", nil];
获得对象为
[output objectAtIndex:1]; // 1 is the index number
关于php - 对于NSMutableArray的Objective-C中的每个循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9973837/