我有一个数组,当我遍历数组时,我也想替换该项目。这是不可能的,如果我这样做会导致崩溃吗?这是代码:
for (int i = 0; i < [highlightItemsArray count]; i++){
//replace the from array with the new one
NSMutableDictionary *tempDictionary = [NSMutableDictionary dictionaryWithDictionary:highlightItem];
[tempDictionary setObject:[newHighlightItem objectForKey:@"from"] forKey:@"from"];
[highlightItemsArray replaceObjectAtIndex:i withObject:tempDictionary];
[indexes addIndex:i];
}
只是想知道这在 Objective-C 中是否合法?如果不是,那么这样做的替代方法是什么?