php - 对于NSMutableArray的Objective-C中的每个循环

标签 php ios foreach nsmutablearray nsarray

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/

相关文章:

php - 比较值但考虑负值

c# - 如何使用 for 循环而不是 foreach 循环?

php session 购物车使用插入记录项目数量两次

javascript - 检查每个购物车标题项的特定样式名称

php - 在 Doctrine 2.x ORM 中使用 REGEXP

javascript - 尝试阻止用户在注销后返回上一页不起作用

php - 仅当另一个字段有值时才为必填字段,否则必须为空

ios - MapBox 托管 map 中的标记不会出现在 TileMill 中

ios - UICollectionView 内的 WebView 动态内容大小

ios - 将 aurioTouch 转换为 Swift 3 时 UnsafePointer<DSPComplex> 的问题