Re: [Pyobjc-dev] pickled Objective-C objects
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-02-23 20:49:03
|
Ronald Oussoren wrote: > 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? I wouldn't care much either way, although I don't see much use in pickling the NSString portion; might as well convert to a unicode object. But ditto: I have no idea how to do that... > Normal Objective-C classes also don't support pickling, [ ... ] Synchronicity! I was thinking about that today. I have written a little app that constructs hundreds of NSBezierPaths at app startup time; I gather it would save a lot of time if I could just load them from a pickle. Would be way cool. For now I think I'll play with NS[Un]Archiver. I don't have a use case, but the reverse would also be very cool: the ObjC wrappers/proxies for Python objects could map the NSCoding protocol to the pickle protocol. > should we add > a reduce method to the proxy that calculates the object state using > NSCoder (where possible)? That sounds fine. > 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). The __reduce__ part of the pickle protocol is completely new to me, so I can't offer any advice at the moment. I'll try to find the time to look into it. Opening a feature-request-bug is definitely a good idea. Just |