所有的开发语言中都会遇到对象的复制问题,通常复制分为浅复制与深复制两种。以Objective-C中的Collections为例,在我们复制一个Collections的具体对象时,比如一个NSArray的对象,我们使用-copy,这样的结果是一个浅层次的复制,在我们对于原对象进行了改动后,所有使用-copy得到的对象都会被改动,这是由于源对象与当前对象是共享一个对象值的。
如果我们想达到深层次复制,Collections也为我们提供了一些方法。仍然以NSArray为例,我们使用-initWithArray:copyItems:就可以实现这种需求。
NSArray *original = [NSArray arrayWithObjects:@″Mimeoscope″, @″Cyclostyle″,nil];
NSArray *shallowCopy = [original copy];
NSArray *deepCopy = [[NSArray alloc] initWithArray:original copyItems:YES];
如上,shallowCopy, 与original指向的是同一个对象. 而deepCopy, 却是一个包含了original值的新的NSArray对象。这就完成了深复制。同样在The NSDictionary与 NSSet中也有相应的方式实现,分别为
–initWithDictionary:copyItems: 与 –initWithSet:copyItems: methods.
分享到:
相关推荐
Programming in Objective-C, 第四版,ePub格式方便在iPad看。 第四版主要更新了 iOS5 与 ARC 的内容,与最新的 Xcode 4.5 匹配。 目录: Table of Contents 1 Introduction Part I: The Objective-C Language 2...
Programming in Objective-C, Fourth Edition Updated for iOS 5 and ARC Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming ...
Book Description Updated for OS X 10.9 Mavericks, iOS 7, and Xcode 5 Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming ...
标签:apache-collections-commons-collections-3.1.jar.zip,apache,collections,commons,collections,3.1,jar.zip包下载,依赖包
2 Programming in Objective-C 7 3 Classes, Objects, and Methods 27 4 Data Types and Expressions 51 5 Program Looping 71 6 Making Decisions 93 7 More on Classes 127 8 Inheritance 151 9 Polymorphism, ...
commons-beanutils-bean-collections-1.7.0.jar
Programming in Objective-C is a concise, carefully written tutorial on the basics of Objective-C and object-oriented programming for Apple's iOS and Mac platforms. The book makes no assumptions ...
常用jar包下载,包括commons-beanutils-1.9.3、commons-collections-3.2.2、commons-collections4-4.1
commons-collections-20040616.jar, commons-collections-3.2-osgi.jar, commons-collections-3.2-sources.jar, commons-collections-3.2.1.jar, commons-collections-3.2.2-javadoc.jar, commons-collections-3.2.2...
赠送jar包:commons-collections-3.2.2.jar; 赠送原API文档:commons-collections-3.2.2-javadoc.jar; 赠送源代码:commons-collections-3.2.2-sources.jar; 赠送Maven依赖信息文件:commons-collections-3.2.2....
标签:aduna-commons-collections-2.2.jar.zip,aduna,commons,collections,2.2,jar.zip包下载,依赖包
Get up to speed on Cocoa and Objective-C, and start developing applications on the iOS and OS X platforms. If you don’t have experience with Apple’s developer tools, no problem! From object-oriented...
[奥莱理] Cocoa Objective-C 开发学习手册 第4版 (英文版) [奥莱理] Learning Cocoa with Objective-C 4th Edition (E-Book) ☆ 图书概要:☆ You’ll learn how to work with the Xcode IDE, Objective-C’s ...
赠送jar包:commons-collections4-4.1.jar; 赠送原API文档:commons-collections4-4.1-javadoc.jar; 赠送源代码:commons-collections4-4.1-sources.jar; 赠送Maven依赖信息文件:commons-collections4-4.1.pom;...
最新的 Programming in Objective-C 第四版!(Epub格式) PC用户可以用filefox的epub插件或Adobe Digital Edition 打开 1 Introduction Part I The Objective-C Language 2 Programming in Objective-C ...
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-bean-collections.jar commons-beanutils-bean-collections.jar
apache-common系列中的重要的成员:apache-common-collections。包中对Java中的集合类进行了一定的补充,定义了一些全新的集合,当然也是实现了Collection接口的,比如Bag,BidiMap。同时拥有新版本的原有集合,比如...
赠送jar包:commons-collections-3.2.2.jar; 赠送原API文档:commons-collections-3.2.2-javadoc.jar; 赠送源代码:commons-collections-3.2.2-sources.jar; 赠送Maven依赖信息文件:commons-collections-3.2.2....
commons-collections-3.2.1-bin