First of all. If you want to extend a class you need to do this:
@interface YourCustomClass : SuperClass
In this manner YourCustomClass
inherits properties and/or methods of your SuperClass
.
About your question, Apple doc says in NSMutableArray Class Reference
There is typically little reason to subclass NSMutableArray. The class
does well what it is designed to do—maintain a mutable, ordered
collection of objects.
You could find the same suggestion in this stackoverflow topic: should-i-subclass-the-nsmutablearray-class.
If you want to subclass NSMutableArray
anyway, see the first link (NSMutableArray Class Reference). You must override 5 methods (see section Methods to Ovveride).
In my opinion you could just use NSMutableArray
in the traditional way: create an NSMutableArray
instance and add objects to it (here a simple example).
NSMutableArray *myArray = [[NSMutableArray alloc] init];
NSNumber *myNumber = [NSNumber numberWithInt:2];
[myArray addObject:myNumber];
Hope it helps.
Edit
To override a method, in your .m file, you need to insert that method and add some logic within it. For example (it's only pseudo code here):
//.h
@interface YourClass: NSMutableArray
@end
//.m
@implementation YourClass
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index
{
// your logic here
}
// do the same for other ones
@end
BUT, again, I suggest you to find a different way to do it because it's quite difficult (in this case) to extends a NSMutableArray
class and obtain a fully functional class like the original one.
Alternative are:
- Use Categories
- Use composition (inside your class use a
NSMutableArray
instance variable)
Finally, I also suggest you to read the following discussion: why-doesnt-my-nsmutablearray-subclass-work-as-expected. In particular, you have to note that
In general, you tend to subclass system classes much less often than
you would in C# or Java.
as Stephen Darlington said.