• 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
Re: mutating method sent to immutable object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mutating method sent to immutable object


  • Subject: Re: mutating method sent to immutable object
  • From: Pete Yandell <email@hidden>
  • Date: Sat, 3 May 2003 17:56:14 +1000

So records is an NSMutableArray of NSMutableDictionaries, correct?

The confusion probably stems from the fact that the line:

records = [[NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"records"]] mutableCopy];

reads in the records as an NSArray of NSDictionaries, then converts that to an NSMutableArray of NSDictionaries. The mutableCopy method doesn't do a deep copy, so the NSDictionaries are not made mutable. This line would do exactly the same thing if written:

records = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"records"]];

or even:

records = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"records"] mutableCopy];


Then, in your tableView:setObjectValue:forTableColumn:row: method, you do this:

theRecord = [records objectAtIndex:rowIndex];
[theRecord setObject:anObject forKey:[aTableColumn identifier]];

This tries to call setObject:forKey: on an NSDictionary object and fails.

I'm working all this out from inspecting and the code not knowing where your error is actually occurring, so I may be completely wrong. :)

Pete Yandell
http://pete.yandell.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >mutating method sent to immutable object (From: Hasan Diwan <email@hidden>)

  • Prev by Date: Re: mutating method sent to immutable object
  • Next by Date: Re: Obj C Runtime Problem
  • Previous by thread: RE: mutating method sent to immutable object
  • Next by thread: Re: mutating method sent to immutable object
  • Index(es):
    • Date
    • Thread