• 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
using copy in nested NSMutableArrays gives immutable objects?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using copy in nested NSMutableArrays gives immutable objects?


  • Subject: using copy in nested NSMutableArrays gives immutable objects?
  • From: Randy <email@hidden>
  • Date: Sat, 15 Nov 2008 22:56:00 -0700

In my program I have nested NSMutableArrays, i.e., each element in a root NSMutableArray is a NSMutableArray.

When I try to grab one of the element NSMutableArrays ......
NSMutableArray *copyOfCurrent = (NSMutableArray *) [[walkerArray objectAtIndex:lastNodeInCurrent] copy];//walkerArray is another NSMutableArray


As soon as I try to alter (insert an element for example) copyOfCurrent I get a "NSInternalInconsistencyException" with the message "mutating method sent to immutable object". It looks like either the objectAtIndex or the copy method is providing something immutable, not an NSMutableArray.

Any idea why that might be happening?

I was able to get around the problem by creating a new NSMutableArray and loading into it the contents of the immutable one like ..

NSMutableArray *copyOfCurrent = (NSMutableArray *) [[walkerArray objectAtIndex:lastNodeInCurrent] copy];
NSMutableArray *fixError = [[NSMutableArray alloc] init];
int k;
for (k = 0; k < [copyOfCurrent count]; k++)
{
fixError[k] = copyOfCurrent[k];
}


But that seems hokey and I would like to understand the cause of the original issue.

Thanks;

Randy
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: using copy in nested NSMutableArrays gives immutable objects?
      • From: Nathan Kinsinger <email@hidden>
  • Prev by Date: Playing around with BWToolKit
  • Next by Date: Re: using copy in nested NSMutableArrays gives immutable objects?
  • Previous by thread: Re: Playing around with BWToolKit
  • Next by thread: Re: using copy in nested NSMutableArrays gives immutable objects?
  • Index(es):
    • Date
    • Thread