Edit2: I restructured all of my headers to have the @class as opposed to the #import language. All .m files now have #import. The problem as posted here seems to be fixed. There are some BAD ACCESS errors now, but while it may be all the same root problem, this manifestation is resolved
Edit: I just found out about something called an "import loop". I'm looking into this being the problem. If anyone has any info about this please let me know.
Unrelated changes are causing impossible errors- I assume there is something deeper or some mistake elsewhere in the program but I just want to confirm this is the case. I have 3 errors and have already rebuild the program in a different Xcode project. I have some code examples, but don't worry- they're (mostly) header files
Error 1
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "PixelSprite.h"
#import "HUDLayer.h"
#import "PixelCharacter.h"
/*typedef enum
{
GameSceneLayerTagGame = 1,
GameSceneLayerTagHUD
}GameSceneLayerTags;*/
@interface GameLayer : CCLayer {
}
@property (assign,readwrite) CGPoint heroStartPoint;
@property (nonatomic, retain) CCTMXTiledMap *tileMap;
@property (nonatomic, retain) CCTMXLayer *background;
@property (assign, readwrite) NSInteger scrollSpeed;
@property (assign, readwrite) PixelCharacter *heroCharacter;
The above line contains a compiler error: Unknown type name 'PixelCharacter'. I know that there is no misspelling. I have even go so far as to copy-paste names of classes and header files just to make sure
+(GameLayer *) sharedGameLayer;
-(id) init;
@end
Error 2
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "HUDButton.h"
@interface HUDLayer : CCLayer {
}
@property (readwrite,assign) CCArray* buttonsArray;
// Working with the buttons
-(void) addHUDButtonOfType:(NSString*)type inSlot:(int)slot;
-(void) addHUDButtonOfType:(NSString*)type;
-(void) removeHUDButton:(HUDButton*)button;
The above line contains a compiler error: Expected a type This makes no sense since a type is clearly posted
-(void) removeHUDButtonOfType:(NSString*)type;
-(void) removeAllButtons;
-(void) buttonsQuery;
@end
Error 3
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
// Get touch location
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
// Verify that touch is on button
BOOL isTouchHandled = CGRectContainsPoint([buttonSprite boundingBox], location);
if (isTouchHandled) {
[buttonSprite setColor:ccRED];
SEL selector = NSSelectorFromString(actionMessage);
GameLayer* layer = [GameLayer sharedGameLayer];
PixelCharacter* heroCharacter = [layer heroCharacter];
The above line contains a compiler warning: incompatible pointer types initializing 'PixelCharacter*' with and expression of type 'int *'
[heroCharacter addToDoQueue:selector];
}
return isTouchHandled;
}
The issue was circular import dependencies.
Apparently, #import in the .h file can sometimes "cover up" problems by making the compiler think that all necessary headers are imported when really it depends on the compile order. The fix and best practice is to use
@class MyClass
in the header and
#import "MyClass.h"
in the .m