Re: mutating method sent to immutable object
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.