Skip to content Skip to sidebar Skip to footer

Pyobjc: How Can One Use Nscoding To Implement Python Pickling?

Title says it all. It seems like it ought be possible (somehow) to implement python-side pickling for PyObjC objects whose Objective-C classes implement NSCoding without re-impleme

Solution 1:

PyObjC does support writing Python objects to a (keyed) archive (that is, any object that can be pickled implements NSCoding).

That’s probably the easiest way to serialize arbitrary graphs of Python and Objective-C objects.

As I wrote in the comments for another answer I ran into problems when trying to find a way to implement pickle support for any object that implements NSCoding due to incompatibilities in how NSArchiver and pickle traverse the object graph (IIRC primarily when restoring the archive).

Solution 2:

Shouldn't it be pretty straightforward?

On pickling, call encodeWithCoder on the object using an NSArchiver or something. Have pickle store that string.

On unpickling, use NSUnarchiver to create an NSObject from the pickled string.

Post a Comment for "Pyobjc: How Can One Use Nscoding To Implement Python Pickling?"