Sure, I know that.
Quote:
Originally Posted by smasher
NSMutableArray has an "addObject:" method, which is equivalent to push, and "removeLastObject:" which you could combine with the "lastObject:" method it inherits from NSArray.
You could subclass from NSMutableArray and just add the methods you need; the only reason not to subclass would be to restrict access to the default methods of NSArray and NSMutableArray. But then you'll have to write your own copy methods, etc.
You could also use a "category" to add your custom methods to NSMutableArray without creating a new class, but that might be a bit confusing if you haven't studied it before. Categories let you add methods (but not variables) to existing classes, even system classes.
That'll give you two pointers to the same stack. You'll want to use [stackA copy] instead if you need a separate stack.
|
I did not try using categories. Maybe that would have done what I wanted.
And I do want two references to the same stack.
Anyway, I finally did create a new class that is NOT a subclass of NSMutableArray, and it behaves JUST like a Stack should. I'll post the code if anyone is interested.
Sam.