如何在objective-c中的"for(id item in items)"循环中获取数组索引?例如,对于NSArray或NSMutableArray.
例如:
for (id item in items) {
// How to get item's array index here
}
如何在objective-c中的"for(id item in items)"循环中获取数组索引?例如,对于NSArray或NSMutableArray.
例如:
for (id item in items) {
// How to get item's array index here
}
我唯一能想到的是:
NSUInteger count = 0;
for (id item in items)
{
//do stuff using count as your index
count++;
}
或者,您可以使用NSArray
的indexOfObject:
消息来获取索引:
NSUInteger index;
for (id item in items)
{
index = [items indexOfObject:item];
//do stuff using index
}