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