NSUserDefaults, an array, and SIGBUS 10
NSUserDefaults, an array, and SIGBUS 10
- Subject: NSUserDefaults, an array, and SIGBUS 10
- From: Michael Mulligan <email@hidden>
- Date: Sun, 28 Jul 2002 23:04:34 -0400
I have a PreferencesController object that brings up a window where the user
fills in some data (to create or modify the settings on a Service object).
When they hit the Save button, it invokes the method I've attached below
(saveService). What this does in a nutshell, is we have an array filled with
Service objects stored in our NSUserDefaults. So this method checks if we're
editting an old Service or creating a new one, replaces the object (or adds
a new one), and then attempts to write this modified array back to the
preferences. The problem is that when it hits the line that should save it
to the preferences, my app crashes with a SIGBUS 10. I have no idea why this
is happening--every object involved with the line in question seems to still
be in memory (I've output their values to check).
And here's the weird part. If I output [[NSUserDefaults
standardUserDefaults] objectForKey:mikeServices] *after* I alter the
visibleServices array but *before* I save it to the UserDefaults, it shows
the changes. However, it does not save them to the actual preferences. So I
know I must be doing something funky with my memory references, but I have
tried everything and have no idea what I'm doing wrong. :-(
Any ideas?
Thanks in advance! :-)
-Mike
//abridged, for your reading pleasure
- (IBAction)saveService:(id)sender {
Service *service;
service=[[Service alloc] initWithTitle:[title stringValue]
startPort:[startPort stringValue] endPort:[endPort stringValue]];
//hide the dialog
[newOrEditDialog orderOut:sender];
//make new service object and insert into array
//if this is to edit an existing service
if([[newOrEditDialog title] isEqualToString:@"Edit Service
"])
{
int row=[tableView selectedRow];
//get the array of Service objects
visibleServices=[[NSUserDefaults standardUserDefaults]
objectForKey:mikeServices];
//make the edit
[visibleServices replaceObjectAtIndex:row withObject:service];
//save it to preferences
//=============================
//NEXT LINE IS WHERE THE SIGBUS 10 HAPPENS
//=============================
[[NSUserDefaults standardUserDefaults] setObject:visibleServices
forKey:mikeServices];
}
//update the tableview
[self updateWindow];
}
-m^2
__________
Hi! I'm a .signature virus! Copy me into your ~/.signature to help me
spread!
__________
23
_______________________________________________
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.