在objective-c中获取for语句中的数组索引 [英] get the array index in for statement in objective-c

查看:82
本文介绍了在objective-c中获取for语句中的数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入了一个愚蠢的混乱......

我不仅要获得数组的值,还要获取值的索引。

在PHP中它很简单: foreach($ array as $ key-> $ value)这里$ key将包含索引值。

是不是有类似的方法在目标c?

我还能做到这一点吗?
请帮忙! :((

I am stuck in a stupid mess...
I want to get not only the value of an array but also the index of the values.
In PHP it's simple: foreach($array as $key->$value) Here $key will contain the index value.
Isn't there a similar approach in objective c?
How else could I achieve this? Please help! :((

推荐答案

与php不同的数组编号为0大小。我猜你在谈论字典。如果是这样的话。你可以用[dict allKeys]获得密钥数组。
所以这样的东西应该可以工作:

Arrays not like in php are numbered 0-size of array. I guess you talking about dictionary's. If so you can get array of key with [dict allKeys]. so something like this should work:

for(id key in [dict allKeys]){
  id value = [dict objectForKey:key];
}

这篇关于在objective-c中获取for语句中的数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆