Re: NSUserDefaults, an array, and SIGBUS 10
Re: NSUserDefaults, an array, and SIGBUS 10
- Subject: Re: NSUserDefaults, an array, and SIGBUS 10
- From: Scott Anguish <email@hidden>
- Date: Mon, 29 Jul 2002 01:59:25 -0400
UserDefaults can't archive your custom objects.. it only knows how to
handle a small number of items
instead you'd need to archive your object to an NSData and THEN add the
NSData to the defaults.. you'll need to reverse the operation when you
load..
this category on NSUserDefaults adds support for archiving NSColor.. you
can see from this how to archive your own data
- (void)setColor:(NSColor *)color forKey:(NSString *)key
{
NSData *data=[NSArchiver archivedDataWithRootObject:color];
[self setObject:data forKey:key];
}
- (NSColor *)colorForKey:(NSString *)key
{
NSData *data=[self dataForKey:key];
return (NSColor *)[NSUnarchiver unarchiveObjectWith
Data:data];
}
On Sunday, July 28, 2002, at 11:04 PM, Michael Mulligan wrote:
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. :-(
_______________________________________________
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.