-
-
Save quantumpotato/3709551 to your computer and use it in GitHub Desktop.
| //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 |
I want the compiler to know about QPBattlefield's properties from a @Class. Compiler flag somewhere.. ?
@class doesn't promise any interface. It just promises that it will exist at compile time. Why can't you just do this again?
#import "QPBattleField.h"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.
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?!

Line 4 & 39. How can I avoid doing this in every subclass of QPBFState or, why doesn't @Class work as I want it to?
I could use a @protocol. I want to know if this is possible.