NSMutableArray
オブジェクトに置き換えたいコンテンツがありますNSNull
。
これが私がすることです:
NSMutableArray* nulls = [NSMutableArray array];
for (NSInteger i = 0; i < myIndexes.count; i++)
[nulls addObject:[NSNull null]];
[stageMap replaceObjectsAtIndexes:myIndexes withObjects:nulls];
どうすればこれをより効率的に行うことができますか? 配列の内容を 1 つずつ置き換えることができるように、NSIndexSet を列挙する方法はありますか?
解決済み
推奨される方法は 2 倍高速であることが判明しました (平均 0.000565 秒 vs 0.001210 秒):
if (myIndex.count > 0)
{
NSInteger index = [myIndex firstIndex];
for (NSInteger i = 0; i < myIndex.count; i++)
{
[stageMap replaceObjectAtIndex:index withObject:[NSNull null]];
index = [myIndex indexGreaterThanIndex:index];
}
}