今天开始讲Objective-C的集合,今天先大概看下Overview。
Most Collections Are Objects
Although it’s possible to use a C array to hold a collection of scalar values, or even object pointers, most collections in Objective-C code are instances of one of the Cocoa and Cocoa Touch collection classes, like NSArray, NSSet and NSDictionary.
These classes are used to manage groups of objects, which means any item you wish to add to a collection must be an instance of an Objective-C class. If you need to add a scalar value, you must first create a suitable NSNumber or NSValue instance to represent it.
Rather than somehow maintaining a separate copy of each collected object, the collection classes use strong references to keep track of their contents. This means that any object that you add to a collection will be kept alive at least as long as the collection is kept alive, as described in Manage the Object Graph through Ownership and Responsibility.
In addition to keeping track of their contents, each of the Cocoa and Cocoa Touch collection classes make it easy to perform certain tasks, such as enumeration, accessing specific items, or finding out whether a particular object is part of the collection.
The basic NSArray, NSSet and NSDictionary classes are immutable, which means their contents are set at creation. Each also has a mutable subclass to allow you to add or remove objects at will.
For more information on the different collection classes available in Cocoa and Cocoa Touch, see Collections Programming Topics.
本文介绍了Objective-C中常用的集合类,如NSArray、NSSet和NSDictionary。这些类用于管理对象组,并使用强引用跟踪其内容,确保对象在集合存活期间不被释放。文章还提到了基本集合类是不可变的,但提供了可变子类来支持动态添加或移除对象。
234

被折叠的 条评论
为什么被折叠?



