Bar*_*ark 145
在OS X 10.6+和iOS SDK 4.0+中,您可以使用以下-enumerateIndexesUsingBlock:消息:
NSIndexSet *idxSet = ...
[idxSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
//... do something with idx
// *stop = YES; to stop iteration early
}];
Run Code Online (Sandbox Code Playgroud)
Eva*_*ski 22
一个while循环应该可以解决问题.使用上一个索引后,它会递增索引.
/*int (as commented, unreliable across different platforms)*/
NSUInteger currentIndex = [someIndexSet firstIndex];
while (currentIndex != NSNotFound)
{
//use the currentIndex
//increment
currentIndex = [someIndexSet indexGreaterThanIndex: currentIndex];
}
Run Code Online (Sandbox Code Playgroud)
Pet*_*sey 20
快速枚举必须产生对象; 由于NSIndexSet包含标量数字NSUInteger,而不包含对象,因此,您无法快速枚举索引集.
假设它可以将它们装入NSNumbers,但那时它不会很快.
| 归档时间: |
|
| 查看次数: |
16841 次 |
| 最近记录: |