lakka  committed 268854b

Updating copying

  • Participants
  • Parent commits 38c4f5d
  • Branches default

Comments (0)

Files changed (1)

File pyobjc-core/Doc/advanced/copying.rst

+It is possible for a Python subclass of an Objective-C class to implement
+the ``NSCopying`` protocol.  Some care must be taken when the superclass
+already implements the protocol. 
+Some ``NSCopying`` compliant Objective-C classes copy the template object
+manually.  In those cases the Python subclass must also copy the additional
+ivars manually.
+Other ``NSCopying`` compliant Objective-C classes use a convenience function
+that creates a shallow copy of the object and all of its ivars.  In those
+cases the Python subclass will not have to explicitly copy all of the ivars.
+However, the ivars in the copy will refer to the same objects as the original,
+and will thus share some state.  As with shallow copies in Python, if any of
+the ivars refer to mutable objects (``list``, ``dict``, etc.) it may be
+desirable to explicitly make shallow or deep copies of the mutable ivars.
+.. note:: 
+    PyObjC might introduce a helper class when you inherit from a class
+    that implements ``NSCopying`` as an internal implementation detail.
+    External code should not rely on the existance of this class.
+.. note::
+    ``SomeClass.copyWithZone_`` should not be implemented unless a
+    superclass already implements ``copyWithZone:``, or else the behavior
+    will be undefined (memory corruption, crashes, etc.).