我有一個NSMutableArray
與我想替換爲NSNull
對象的內容。用單個對象替換多個數組內容?
這是我做的:
NSMutableArray* nulls = [NSMutableArray array];
for (NSInteger i = 0; i < myIndexes.count; i++)
[nulls addObject:[NSNull null]];
[stageMap replaceObjectsAtIndexes:myIndexes withObjects:nulls];
我該怎麼做更有效? 有沒有辦法枚舉NSIndexSet,所以我可以逐個替換數組內容?
解決
建議的方法原來是快2倍(平均0.000565s VS 0.001210s):
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];
}
}
這是行爲效率低下嗎?即在分析應用程序時,您看到此代碼片段中的大幅減速? – 2009-04-12 06:48:07