I have these two classes MobRec & MobDef and I want to reference an array pointer of (MobDef) *mobInfo from MobRec. #import the mobdefs.h file in MobRec.h or .m but no luck any ideas?
MobRec.h
// Basic class unit
@interface MobRec : NSObject {
NSString *mName;
int speed;
}
@end
MobDef.h
// Master Class holding an array of units
@interface MobDef : NSObject {
NSMutableArray *mobInfo;
}
@property(retain) NSMutableArray *mobInfo;
@end
MobDef.m
@synthesize MobInfo;
- (id)init { // to add a new node开发者_StackOverflow社区 and initialize it
mobInfo = [[NSMutableArray alloc] init];
MobRec *aNewMobRec = [[MobRec alloc] init];
[mobInfo addObject:aNewMobRec];
[aNewMobRec release];
}
The problem is that individual files have no knowledge of other files in your project, since Objective-C is a derivative of C. You need to #import
the header files of any other classes that you need to use:
// ModDef.m
#import "MobDef.h"
#import "ModRec.h"
@implementation MobDef
@synthesize mobInfo; // case matters here
- (id)init
{
mobInfo = [[NSMutableArray alloc] init];
MobRec* aNewMobRec = [[MobRec alloc] init];
[mobInfo addObject:aNewMobRec];
[aNewMobRec release];
}
@end
Well, your @synthesize
doesn't match @property
declaration - you're declaring properties for mobInfo
but generating synthesized accessors for MobInfo
.
Of are you getting some other error?
精彩评论