Using multiple files in iPhone app
Im starting a new iPhone app, and Im sick of doing them the 'lazy way'; i.e. all of the 开发者_如何转开发code in one view controller. I want to control the levels form a different .m (or with XML). How do I, say, have a CGPoint declared in Level.h, controlled in Level.m, and accessed in Game.m?
Thanks, Conor
ClassA.h
@interface ClassA : BaseClass
{
CGPoint point;
}
@property(nonatomic, assign) CGPoint point;
@end
ClassB.h
#import "ClassA.h"
@interface ClassB : BaseClass
{
ClassA classa;
}
@property(nonatomic, retain) ClassA classa;
@end
ClassB.m
CGPoint localPoint = classa.point
Try not to think in terms of code in file A talking to code in file B. This is object oriented programming, so think in terms of objects talking to each other. Any object can talk to any other object to which it has a reference (pointer). Organizing your program so that the objects that need to talk to each other can do so is one of the most important tasks that you do as a software developer.
Solved!
in Levels.h:
@interface Levels : NSObject {
}
+(CGPoint)levelController;
in Levels.m:
+(CGPoint)levelController {
CGPoint wall_01;
wall_01 = CGPointMake(300, 100);
return wall_01;
}
in Game.m:
test = [Levels levelController];//in any method you want, just import "Levels.h"
精彩评论