[Pyobjc-dev] pickled Objective-C objects
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-02-23 16:11:39
|
I noticed the other day that our unicode subclass doesn't support pickling. Should we add support for pickling, and if so how? Should instances of our subclass be pickled just like 'normal' unicode objects (although I have no idea how to do that), or as NSString values? Normal Objective-C classes also don't support pickling, should we add a reduce method to the proxy that calculates the object state using NSCoder (where possible)? It might also be possible to provide a default implementation of initWithCoder: and encodeWithEncoder: if the parent class implements those. The default encodeWithEncoder: implementation would call the superclass implementatation, then a NSDictionary containing the Objective-C instance variables and python __slots__ and then an NSDictionary containing the python __dict__. The __reduce__ method would use the result of [self encodeWithEncoder:] as the object state, and the restore function would use that state to restore the object using initWithCoder:. Does this look like a valid approach? If it is I'll probably file a bug report containing this scheme (I don't think I'll get around to implementing this anytime soon). Ronald |