最近看书看到一种新的实现深复制对象的技术,使用Foundation的归档技术,下面是代码:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:dataArray];
NSMutableArray *dataArray2 = [NSKeyedUnarchiver unarchiveObjectWithData:data];
上述即实现了将dataArray深复制给dataArray2,另外一种简便写法是:
dataArray2 = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedUnarchiver archiveObjectWithRootObject:dataArray]];