PyObjC:如何使用 NSCoding 来实现 Python 酸洗? [英] PyObjC: How can one use NSCoding to implement python pickling?

查看:106
本文介绍了PyObjC:如何使用 NSCoding 来实现 Python 酸洗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题说明了一切.似乎应该可以(以某种方式)为其 Objective-C 类实现 NSCoding 的 PyObjC 对象实现 python 端酸洗,而无需从头开始重新实现所有内容.也就是说,虽然值语义成员可能很简单,但按引用对象图和条件编码可能很棘手.如何让双方在对象图部分协作"?

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-implementing everything from scratch. That said, while value-semantic members would probably be straightforward, by-reference object graphs and conditional coding might be tricky. How might you get the two sides to "collaborate" on the object graph parts?

推荐答案

PyObjC 确实支持将 Python 对象写入(键控)存档(即,任何可以被酸洗的对象都实现 NSCoding).

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

这可能是序列化 Python 和 Objective-C 对象的任意图的最简单方法.

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

正如我在另一个答案的评论中所写的那样,由于 NSArchiver 和 pickle 遍历对象图的方式不兼容(IIRC 主要是在恢复存档).

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).

这篇关于PyObjC:如何使用 NSCoding 来实现 Python 酸洗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆