私のアプリケーションでは、のコピーを作成する必要があります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 も自動的に変更されます。