Mutating method sent to immutable object
Mutating method sent to immutable object
- Subject: Mutating method sent to immutable object
- From: Bruce Truax <email@hidden>
- Date: Sun, 10 Oct 2004 21:36:00 -0400
I have mutable array and each object in this array contains another mutable
array defined as follows:
NSMutableArray *extraDataArray;
When I want to add an object to this array I do the following:
NSMutableArray *edArray = [aSurface extraDataArray];
[aSurface setExtraDataArray:[edArray addObject: theExtraData]];
This assures that the KVO bindings work properly but I get the following
error:
2004-10-10 21:16:47.198 AccosX[4627] Exception raised during posting of
notification. Ignored. exception: *** -[NSCFArray addObject:]: mutating
method sent to immutable object
I also tried replacing the above two lines of code with:
[[aSurface extraDataArray] addObject: theExtraData];
And again I get the same error.
My accessors for the extra data array are:
- (NSMutableArray *)extraDataArray {
return [[extraDataArray retain] autorelease];
}
- (void)setExtraDataArray:(NSMutableArray *)newExtraDataArray {
if (extraDataArray != newExtraDataArray) {
[extraDataArray release];
extraDataArray = [newExtraDataArray copy];
}
}
And the array is initialized using:
[self setExtraDataArray:[NSMutableArray arrayWithCapacity:20]];
I also have an
- (void)insertObject:(id)anObject inExtraDataArrayAtIndex:(unsigned
int)index
Method and it gives the same error when I try to insert an object into the
array.
Does anyone have any suggestions?
Thanks.
Bruce
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden