最近看书看到一种新的实现深复制对象的技术,使用Foundation的归档技术,下面是代码:
1
2 |
NSData *data = [ NSKeyedArchiver
archivedDataWithRootObject:dataArray]; NSMutableArray
*dataArray2 = [ NSKeyedUnarchiver
unarchiveObjectWithData:data]; |
上述即实现了将dataArray深复制给dataArray2,另外一种简便写法是:
1 |
dataArray2 = [ NSKeyedUnarchiver
unarchiveObjectWithData:[ NSKeyedUnarchiver
archiveObjectWithRootObject:dataArray]]; |
OC中没有实现NSCopying技术时的深复制技术,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/robinsons/p/3735239.html