How to create a typed stack using Objective-C

Posted by Xetius on Stack Overflow See other posts from Stack Overflow or by Xetius
Published on 2011-03-09T22:49:52Z Indexed on 2011/03/10 0:10 UTC
Read the original article Hit count: 375

I can create a stack class quite easily, using push and pop accessor methods to an NSArray, however. I can make this generic to take any NSObject derived class, however, I want to store only a specific class in this stack.

Ideally I want to create something similar to Java's typed lists (List or List) so that I can only store that type in the stack. I can create a different class for each (ProjectStack or ItemStack), but this will lead to a more complicated file structure.

Is there a way to do this to restrict the type of class I can add to a container to a specific, configurable type?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about collections