• 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: p3consulting <email@hidden>
  • Date: Sat, 3 May 2003 09:08:23 +0200

I'm writing a small program to keep track of my wine collection. The entire source is below, and it's giving me the above error. Needless to say, I can't figure out what's wrong.
@implementation WineX
- - (id)init {
if (self = [super init]) {
records = [[NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:@"records"]] mutableCopy];


Are you sure the mutableCopy do make the objects of the array also mutable or only the array itself is mutable after the call ?
You may have two different problems here:
1. mutableCopy is (probably) not recursive: to check this hypothesis do a small test on the class of the members of the array ( a NSLog("%@",[records objectAtIndex:0]) will be enough to see if the object is mutable or not)
2. mutableCopy does nothing more than a copy when its receiver is already mutable, to check if this is the case just do
[ [[NSUserDefaults standardUserDefaults] arrayForKey:@"records"] mutableCopy];

Pascal

P3 Consulting
email@hidden
http://www.p3-consulting.net
_______________________________________________
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.

  • Prev by Date: Undo support of NSTextStorage
  • Next by Date: Re: mutating method sent to immutable object
  • Previous by thread: Re: mutating method sent to immutable object
  • Next by thread: How to call AS method from Cocoa ?
  • Index(es):
    • Date
    • Thread