Created
September 12, 2012 20:11
-
-
Save quantumpotato/3709551 to your computer and use it in GitHub Desktop.
Avoiding multiple #import .h when using @Class forward declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//QPBattlefield.h | |
#import "ClonePilotBattlefield.h" | |
#import "QPBFState.h" | |
#import "QPBFTitleState.h" | |
#import "QPBFDrawingState.h" | |
#import "QPBFInputConstants.h" | |
@interface QPBattlefield : ClonePilotBattlefield | |
@property (nonatomic, retain) QPBFState *currentState; | |
@property (nonatomic, retain) QPBFTitleState *titleState; | |
@property (nonatomic, retain) QPBFDrawingState *drawingState; | |
- (void)changeState:(QPBFState *)state; | |
@end | |
//QPBFState.h | |
#import <Foundation/Foundation.h> | |
@class QPBattlefield; | |
@interface QPBFState : NSObject | |
@property (nonatomic, retain) QPBattlefield *f; | |
- (void)addTouch:(CGPoint)l; | |
- (id)initWithBattlefield:(QPBattlefield *)field; | |
@end | |
//QPBFTitleState.m ((inherits from QPBFState)) | |
#import "QPBFTitleState.h" | |
#import "QPBattlefield.h" | |
@implementation QPBFTitleState | |
- (void)addTouch:(CGPoint)l { | |
if (GetDistance(l, self.f.player.l) <= QPBF_PLAYER_TAP_RANGE) { | |
[self.f changeState:self.f.drawingState]; | |
} | |
} | |
@end |
Suspicions confirmed. Thanks everyone.
Circular #imports would work if only ..
http://www.programmers-pain.de/wp-content/uploads/recursion.jpg
@subdigital Definitely can. Just seeing if I could avoid typing that one extra line N*subclasses times in this design.
You can put it in your PCH file maybe.
@subdigital I'm about to get a haircut. Inspired.
omgwtfbbq haircut?!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All @Class does is tell a class that "a class with this name does/will exist". There's no information about what the class contains until you import the header.