-7

enter image description here

I have taken three arrays. One array for saving image data and remaining two arrays image names and dates.

While deleting row I'm getting this error:

NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'

How to handle this?

Vinodh
  • 5,262
  • 4
  • 38
  • 68
SWAMY CHUNCHU
  • 225
  • 5
  • 14
  • Please update your question with your relevant code. – rmaddy Nov 04 '16 at 05:39
  • 1
    So you need array to save image data, image name and date, right. Ok, just take a object class with three properties, then add the object class object to array, then manipulate the array, no need to take three different arrays. And your error seems that you are taken NSArray and deleting object from an NSArray, which is not mutable. Take mutable array – Sailendra Nov 04 '16 at 05:46
  • `mutating method sent to immutable object` should make it clear that you are trying to mutate a NSArray whereas you should been using an NSMutableArray instead. – NSNoob Nov 04 '16 at 05:47
  • i have uploaded image can u have see the image please, i'am taking 3 arrays one for images 2nd for image names 3rd one current date i need to delete one image so each row contain 3 objects na how delete this ? – SWAMY CHUNCHU Nov 04 '16 at 05:58
  • Possible duplicate of [iOS delete a tableview row](http://stackoverflow.com/questions/18961581/ios-delete-a-tableview-row) – jose920405 Nov 04 '16 at 12:56

2 Answers2

0

You need to use NSMutableArray instead of NSArray

KKRocks
  • 8,222
  • 1
  • 18
  • 84
0

Simple and optimize way to achieve your functionality

Take a NSObject class like

#import <Foundation/Foundation.h>

@interface YourClassName : NSObject

@property (nonatomic, strong) NSString *imgName;
@property (nonatomic, strong) NSData *imgData;
@property (nonatomic, strong) NSString *imgDate;

@end

Then, add the object of the class to NSMutableArray, then mutate it as your wish. Just delete from one array rather than deleting from three different arrays, which is very confusing and may conflicts.

Or

Just Use NSMutableArray instead of NSArray. If you are doing this already, then check NSMutableArray contains NSArray type values, which can't be immutable.

Thanks

Sailendra
  • 1,318
  • 14
  • 29
  • NSMutableArray *imagesArray; NSMutableArray *namesArray; NSMutableArray *datesArray; taking 3 mutable arrays – SWAMY CHUNCHU Nov 04 '16 at 06:07
  • why? Just take object class and add the object to a single array. When the array size increases, may cause memory leak issue in future... – Sailendra Nov 04 '16 at 06:34
  • i have taken 3 mutable arrays one array have image data another array image names and third one images dates, see above image iam showing like that . if i wont to delete one image i need to remove that particular row indexes that image data and name and that date , if click the delete button it was showing this error "mutating method sent to immutable object'" – SWAMY CHUNCHU Nov 04 '16 at 10:43
  • k, that's why I am telling you to create a object class sub-class of NSObject, as I described above. Make one array (NSMutableArray) of objects, having your image data, name and date. In table cell get the object and set in the cell. When remove/delete, just delete that object from the array. Simple – Sailendra Nov 04 '16 at 11:02
  • The error is coming due to lots of complex code you have written. Just avoid that by using array of object – Sailendra Nov 04 '16 at 11:05
  • In commitEditingStyle method, you have written 3 if statements to remove name, image and date. Don't do that, just use array of objects, and one line code to delete i.e [yourObjectArray removeObjectAtIndex:indexPath.row]; – Sailendra Nov 04 '16 at 11:08