What I really like in C# are generic lists. A list that can contain only one type of objects. Is there something like a generic list in Cocoa/Objective-C? As far I only know NSArray who will take a pointer to any object.
Objective-C doesn't support generic programming. You could always use Objective-C++ and an STL list.
Wanting this is often a sign of a weak design. NSArray is immutable, so it will not "take a pointer to any object" and presumably already contains the correct objects when handed to you. What I assume you're more worried about is an NSMutableArray where you think other parts of your code might add the wrong sort of object. But have a look at Cocoa itself; it's incredibly rare to expose a mutable array as part of a class's design.
Instead, you generally expose an NSArray and a couple of methods for modifying that array. Something along the lines of:
@class Foo : NSObject
- (NSArray *)bars;
- (void)addBar:(Bar *)bar;
- (void)removeBar:(Bar *)bar;
@end
This generally stops wrong objects being inserted simply by having a compiler warning, and then of course you can add assertions within -addBar: and -removeBar: if you wish too.
Why doesn't Objective-C support generic programming? Both NSNumber and NSString support compare:, so why couldn't one write (e.g.) a generic version of min or max?
My question is rhetorical and directed towards Ferruccio's statement that Objective-C doesn't support generic programming. More to the original question, there may not be a standard "NSList", but I don't see why one couldn't be implemented, and the Cocoa collections which do exist like NSArray can contain heterogeneous objects, so they might as well be generic in the sense of the STL (not type-safe, but generic.) Less relevant to the original question but more relevant to the issue of generic programming, I mean to say that because Objective-C classes appear to implement methods like compare:, there IS no reason one could not write free functions which operate on Objective-C class instances in much the same way that templated functions in the STL operate on C++ class instances. Objective-C may not be generic in exactly the same way that C++ is, but it could support a style of programming not entirely unlike generic programming ala the STL.