I would like to create my own custom NSMutableArray of my custom objects:
@interface Course : NSObject {
NSString *className;
NSString *classGrade;
NSInteger creditHours;
}
This class will store an array of courses :
@interface AllCourses : NSObject : NSMutableArray{
NSMutableArray *arrClasses;
}
I would like “AllCourses” to inherit from NSMutableArray so i can use it like any other NSMutableArray Object and add\remove courses from it and load it into a tableView etc…
So my question is ,if u would be so kind, is what my implementation of “AllCourses” should look like ?
First of all. If you want to extend a class you need to do this:
In this manner
YourCustomClassinherits properties and/or methods of yourSuperClass.About your question, Apple doc says in NSMutableArray Class Reference
You could find the same suggestion in this stackoverflow topic: should-i-subclass-the-nsmutablearray-class.
If you want to subclass
NSMutableArrayanyway, see the first link (NSMutableArray Class Reference). You must override 5 methods (see section Methods to Ovveride).In my opinion you could just use
NSMutableArrayin the traditional way: create anNSMutableArrayinstance and add objects to it (here a simple example).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):
BUT, again, I suggest you to find a different way to do it because it’s quite difficult (in this case) to extends a
NSMutableArrayclass and obtain a fully functional class like the original one.Alternative are:
NSMutableArrayinstance 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
as Stephen Darlington said.