深拷贝

来源:互联网 发布:沈飞 成飞 知乎 编辑:程序博客网 时间:2024/05/01 07:04

在做深拷贝的时候,需要注意自定义的对象,需要遵守NSCopying协议,同时需要实现copeWithZone协议方法,否则在执行copyItems:YES的时候,会发生断错误。

The NSCopying protocol declares a method for providing functional copies of an object. The exact meaning of “copy” can vary from class to class, but a copy must be a functionally independent object with values identical to the original at the time the copy was made. A copy produced with NSCopying is implicitly retained by the sender, who is responsible for releasing it.

NSCopying declares one method, copyWithZone:, but copying is commonly invoked with the convenience method copy. The copy method is defined for all objects inheriting from NSObject and simply invokescopyWithZone: with the default zone.

0 0