Having some difficulty with what I thought would be straight forward. I am trying to make an array of class objects but running into different problems. The goal was to create one class that held an array of another class of objects.
Any help appreciated:
// Basic class unit
@interface MobRec : NSObject {
NSString *MName;
int Speed;
}
@end
// Master Class holding an array of units
@interface MobDefs : NSObject {
MobRec *MobInfo;
}
@property(retain) MobRec *MobInfo;
@end
@synthesize MobInfo;
1) From reading it seems I should create and NSMutableArray but how do you declare an NSMutableArray of custom class objects? All iterations I try cause errors. Previously I had predefined the size in the class as MobInfo[20]; but that didnt seem to be good for anything.
2) How do you properly @Synthesize an array of class objects?
NSMutableArray doesn’t have any type checking as you add (or read) from it, so you can add any objects you want to it.
In this case I’d have something like:
I’ve included the basics for adding to the array as well so you can see how its used. Oh and don’t forget you have to release the MobInfo in the dealloc method.
But mostly look at NSMutableArray