mutating method sent to immutable object
mutating method sent to immutable object
- Subject: mutating method sent to immutable object
- From: Hasan Diwan <email@hidden>
- Date: Fri, 2 May 2003 11:09:00 -0700
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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];
[dataDisplay setDataSource:self];
[dataDisplay setDelegate:self];
[dataDisplay setDoubleAction:@selector(doubleClick:)];
if (nil == records) {
records = [[NSMutableArray array] retain];
}
[self newRecord:self];
}
return self;
}
- - (void)createNewRecord {
NSMutableDictionary *d = [[NSMutableDictionary alloc] init];
[records addObject:d];
[d release];
}
- - (void)applicationWillTerminate:(NSNotification *)n {
[[NSUserDefaults standardUserDefaults] setObject:records
forKey:@"records"];
}
- - (void)dealloc {
[[NSUserDefaults standardUserDefaults] synchronize];
[records release];
[super dealloc];
}
- - (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theRecord, theValue;
theRecord = [records objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
- - (void)tableView:(NSTableView *)aTableView
setObjectValue:anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theRecord;
NSLog(@"%@", records);
theRecord = [records objectAtIndex:rowIndex];
[theRecord setObject:anObject forKey:[aTableColumn identifier]];
return;
}
- - (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [records count];
}
- - (IBAction)newRecord:(id)sender {
[self createNewRecord];
[dataDisplay reloadData];
}
@end
@implementation NSMutableDictionary (UnableToSetNilForKey)
- - (BOOL)unableToSetNilForKey:(NSString *)k {
if ([k isEqualToString:@"Score"]) {
[self setObject:[NSNumber numberWithInt:0] forKey:k];
return YES;
}
return NO;
}
@end
Hasan Diwan {
http://ibn.com/~hdiwan}
OpenPGP Fingerprint: 275D 0E84 550C D92A 4A56 732C 8528 2579 E6E9 4842
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (Darwin)
iD8DBQE+srRDhSgleebpSEIRAtIHAJ4hNfYENG9NY7MMFyKLb0QVvnK9UgCgjFzT
IAQYJNSWZj3RChiqEvsQG64=
=/0mh
-----END PGP SIGNATURE-----
_______________________________________________
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.