Problem with NSConnection between threads and archiving?
Problem with NSConnection between threads and archiving?
- Subject: Problem with NSConnection between threads and archiving?
- From: Matt Tenenbaum <email@hidden>
- Date: Mon, 29 Nov 2004 15:30:45 -0500
My application delegate responds to -applicationWillTerminate:, in
order to serialize the contents of a particular object to the standard
user defaults. I was doing something like the following:
(pardon the following Mail-based code fragment)
- (void) applicationWillTerminate:(NSNotification *)note {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// ...
[defaults setObject:[NSKeyedArchiver archivedDataWithRootObject:[self
objectToPersist]]
forKey:IdentifierForPersistedObject];
[defaults synchronize];
}
This used to work, but recently I set up a pair of NSConnection
instances in order to safely allow some other work to happen in a
separate thread (in almost exactly the way that the examples
illustrate). That seems to have caused some problems, although it's not
clear to me why.
In particular, now the -[NSUserDefaults setObject:forKey:] call causes
the debugger to fail, throwing an exception. Attempting to determine
whether the exception was coming from the archiving process or the user
defaults process, I broke the archiving process into two steps:
NSData *thePersistedData = [NSKeyedArchiver
archivedDataWithRootObject:[self objectToPersist]];
[defaults setObject:thePersistedData
forKey:IdentifierForPersistedObject];
In this case, the exception is thrown in the +[NSKeyedArchiver
archivedDataWithRootObject:] call (and it never makes it to the
NSUserDefaults message. In particular, the exception type is
NSInternalInconsistencyException (which I guess has to do with an
assertion failing), and the reason is "methodSignature for bad wire
type: 3".
It's not clear to me, even with the presence of the other thread, why
archiving this instance would somehow become problematic
(unscientifically, coding worked fine before setting up the
NSConnection instances and didn't work afterword). FWIW, one of the
constitutive objects in the persisted object is an argument to a
message sent to the other thread (via the sibling NSConnection
instance). Is there any reason in general to expect problems with
NSConnection and NSKeyedArchiver?
I'm most perplexed, and can't seem to find anything conclusive about
this in previous messages, etc. Any suggestions would be greatly
appreciated.
Thanks
-matt
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden