• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Mutating method sent to immutable object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Mutating method sent to immutable object
      • From: Scott Stevenson <email@hidden>
  • Prev by Date: Re: Getting objectSpecifier right...
  • Next by Date: Re: Mutating method sent to immutable object
  • Previous by thread: Re: Application behaves strange / doesn't start correctly
  • Next by thread: Re: Mutating method sent to immutable object
  • Index(es):
    • Date
    • Thread