Tuesday 15 September 2015

cocoa - Any reason to not use existing NSCoding methods to implement NSCopying -



cocoa - Any reason to not use existing NSCoding methods to implement NSCopying -

is there reason given class implements nscoding implementation of copywithzone: shouldn't implemented using pattern:

-(instancetype)copywithzone:(nszone *)zone{ homecoming [nskeyedunarchiver unarchiveobjectwithdata:[nskeyedarchiver archiveddatawithrootobject:self]]; }

just efficiency — encoding/decoding cost , total memory footprint.

suppose had object 4 immutable instance variables. if implement custom copy you'll allocate 1 instance of object, give ownership of 4 instance variables.

if encode , decode there'll processing cost of two-way serialisation , you'll end new copies of each of instance variables.

cocoa cocoa-touch nscoding nscopying

No comments:

Post a Comment