开发者

Objective C equivalent to Java's ArrayList

开发者 https://www.devze.com 2023-01-09 10:29 出处:网络
Just wondering if there is an equivalent to Java\'s Array开发者_开发技巧List in Objective-C? Or something that can be used to store objects/data that does not have a set size.

Just wondering if there is an equivalent to Java's Array开发者_开发技巧List in Objective-C?

Or something that can be used to store objects/data that does not have a set size.

Thanks.


As others have pointed out, NSArray/NSMutableArray are what you're looking for.

Coming from the Java world, you may find that Cocoa's collection offerings feel quite paltry. In fact, the functionality is quite extensive. The NSArray, NSDictionary, and NSSet are, in fact, class clusters, meaning that the public API is an "abstract" class. When you initialize one of the collections, what you get back is, in fact, a concrete implementation tailored for the data you provide. These implementations can also change the concrete implementation at run time if the data changes (e.g. it grows in size). This is all possible due to Objective-C's much more dynamic run time than Java's static typing (and security) will allow. The class cluster strategy thus hides many of the implementations of, e.g. the java.util.List interface, behind a single API.

The Cocoa frameworks are somewhat limited in compound data structures (i.e. those built on top of "primitive" arrays, sets, and dictionaries). You may find that the excellent, open source CHDataStructures fills in many of the gaps.


NSMutableArray. You can add objects to it as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消