NSArray losing its data
NSArray losing its data
- Subject: NSArray losing its data
- From: Hasan Diwan <email@hidden>
- Date: Sun, 17 Nov 2002 02:12:46 -0800
In createNewTransactions, an NSMutableDictionary is added to an
NSMutableArray. By the time, it's saved, all data from the array is
gone. Without further commentary, here's the code, the declaration for
trasactions is in a comment above the createNewTransaction definition:
// NSMutableArray *transactions = [[[NSMutableArray alloc]
initWithCapacity:0] retain];
- (void)createNewTransaction {
NSMutableDictionary *t;
t = [[NSMutableDictionary alloc] init];
[transactions addObject:t];
#ifdef DEBUG
NSLog(@"%@", [transactions lastObject]);
#endif
}
- (IBAction)save:(id)sender {
[[NSSavePanel savePanel] beginSheetForDirectory:[[NSString
stringWithString:@"~/Documents"] stringByExpandingTildeInPath]
file:@".xml"
modalForWindow:[NSApp keyWindow]
modalDelegate:self
didEndSelector:@selector(didEndSaveSheet:returnCode:contextInfo:)
contextInfo:NULL];
}
- (void)didEndSaveSheet:(NSSavePanel *)savePanel
returnCode:(int)returnCode contextInfo:(void *)contextInfo {
[savePanel orderOut:nil];
if (returnCode == NSOKButton) {
NSString *filename = [savePanel filename];
[[NSApp keyWindow] setTitle:filename];
[self updateChangeCount:NSChangeCleared];
#ifdef DEBUG
NSLog(@"%@", [transactions description]);
#endif
if (![transactions writeToFile:filename atomically:YES]) {
NSBeep();
}
}
}
Thanks in advance!
Hasan Diwan
OpenPGP KeyID: 0xBE42DCA6
Fingerprint: 1CB0 47E3 0A24 DAC1 DCCA 4225 F166 40C2 BE42 DCA6
http://www.cs.rpi.edu/~diwanh/gpg.key
[demime 0.98b removed an attachment of type application/pgp-signature which had a name of PGP.sig]
_______________________________________________
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.