I wonder if Objective-C offers support for Lists
? Or .. is NSMutableArray
a way to go, instead?
Yes NSMutableArray
(Mac, iOS) would in most cases be the appropriate class for lists (with NSArray
being the immutable counterpart).
Contrary to Java's collection classes Objective-C's (or rather Foundation's) arrays are opaque class clusters that completely hide their implementation.
Edit: snip (see comment by orange80)
While Java has a ton of collection classes such as:
HashSet
TreeSet
LinkedHashSet
ArrayList
LinkedList
PriorityQueue
HashMap
TreeMap
LinkedHashMap
WeakHashMap
IdentityHashMap
CopyOnWriteArrayList
CopyOnWriteArraySet
EnumSet
EnumMap
ConcurrentLinkedQueue
LinkedBlockingQueue
ArrayBlockingQueue
PriorityBlockingQueue
DelayQueue
SynchronousQueue
ConcurrentHashMap
Objective-C however (again, actually the Foundation SDK) only provides a very limited number of collection classes:
CFMutableDictionary
CFMutableBag
CFMutableBitVector
CFMutableSet
CFMutableArray
CFBinaryHeap
CFMutableTree
or preferably their NS-equivalents:
NSMutableDictionary
NSDictionary
NSMutableSet
NSSet
NSCountedSet
NSMutableArray
NSArray
For a full insight in the matter I recommend this read: http://ridiculousfish.com/blog/posts/array.html (the author is a member of Apple's Foundation Team)
Generally speaking, you'll want to use NSMutableArray
for equivalent behaviour (though the implementation is very different.) You also have the option of using CFMutableArray
(a C-based API that is a little more flexible than NSMutableArray
and is toll-free bridged with it.) If you're using C++ rather than (or in addition to) Objective-C, you have any of the STL collection types (such as std::list<T>
, std::vector<T>
, etc.) whose suitability will depend on your exact use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With