在我的应用程序中,我需要创建一个NSMutableArray
. 目前我正在使用mutableCopy
方法。但是当我修改复制的数组时,原始数组也被修改了。请告诉我如何创建新副本NSMutableArray
。这是代码
delegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
self.mainImagesArray = [[NSMutableArray alloc]initWithArray:[delegate.arrayForCarCaptureImages mutableCopy]];
我在这里修改
UIImage *filteredImage =[[[[self.mainImagesArray objectAtIndex:i]valueForKey:valueVheck] objectAtIndex:j] copy];
filteredImage =[filteredImage brightness:(1+sliderValue-0.5)];
[[[self.mainImagesArray objectAtIndex:i]valueForKey:valueVheck]removeObjectAtIndex:j];
[[[self.mainImagesArray objectAtIndex:i] valueForKey:valueVheck]insertObject:filteredImage atIndex:j];
执行后,arrayForCarCaptureImages 也会自动修改。