如何在 Objective-c 中的“for (id item in items)”循环中获取数组索引?以 NSArray 或 NSMutableArray 为例。
例如:
for (id item in items) {
// How to get item's array index here
}
最佳答案
或者,您可以使用 -enumerateObjectsUsingBlock:
,它将数组元素和相应的索引作为参数传递给 block :
[items enumerateObjectsUsingBlock:^(id item, NSUInteger idx, BOOL *stop)
{
…
}];
奖励:对数组元素并发执行 block 操作:
[items enumerateObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(id item, NSUInteger idx, BOOL *stop)
{
…
}];
关于objective-c - 如何在 "for (id item in items)" objective-c 循环中获取数组索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5812132/
相关文章:
iphone - 改变 setContentOffset 的速度 :animated:?
objective-c - 核心数据 : error: Failed to call designa
ios - 如何将 NSDate 转换为相对格式 "Today","Yesterday","a we
ios - 为什么 UICollectionView 的 UICollectionViewCell
objective-c - 是否可以将 NSInteger 转换为 NSNumber?
iphone - 滚动后检测 UITableView 中的当前顶部单元格