Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C header file not recognizing custom object as a type
    primarykey
    data
    text
    <p>I'm working on a game for iPad using cocos2d which involves a board filled with different types of tiles. I've created a custom class called <code>Tile</code> as a general template for tiles and a few subclasses of <code>Tile</code> which have different properties and methods. I've also created a class called <code>Board</code> which, among other things, keeps track of the locations of all the tiles using a special coordinate system. </p> <p>For some reason, in the <code>Board</code> class, the compiler doesn't seem to be recognizing <code>Tile</code> as a type of object, even though I've added <code>#import "Tile.h"</code> at the top of the file. </p> <p>Here's the relevant code (just ask if there's other parts of the code you want to see):</p> <p><strong>Tile.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "cocos2d.h" #import "Board.h" @interface Tile : NSObject -(void) updateNeighbors; @property (nonatomic, retain) CCSprite* sprite; @property (assign) CGPoint coords; @property (assign) CGPoint positionInPoints; @property (nonatomic, retain) NSMutableArray *neighbors; @end </code></pre> <p><strong>Board.h</strong></p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "cocos2d.h" #import "Tile.h" @interface Board : NSObject +(Board*)sharedBoard; - (void) putTile: (Tile*) tile AtIndex: (CGPoint) index; //&lt;-- error here! - (void) replaceTileAtIndex: (CGPoint) index1 WithTileAtIndex: (CGPoint) index2; - (Tile*) tileAtIndex: (CGPoint) index; //&lt;-- error here! - (void) populate; @property (nonatomic, retain) NSMutableArray *tiles; @property (nonatomic, retain) NSString *type; @property (assign) CGPoint size; @end </code></pre> <p>This code will not even build and I'm getting the following error where indicated:</p> <blockquote> <p>Expected '(' before 'Tile'</p> </blockquote> <p>If I change the type from <code>(Tile*)</code> to <code>(NSObject*)</code>, it fixes the error, which leads me to believe that <code>Tile</code> is not being recognized as a type of object.</p> <p>I've searched via Google and this site and cannot figure out why this is happening.</p> <hr> <h2>Update</h2> <p>Dumb mistake; easy to fix. </p> <p>As you all have pointed out the problem is that the two header files are importing each other, which is not allowed. For now, I've fixed the problem by moving the #import "Board.h" statement to Tile.m, since it isn't needed in the header file. Later on, if I decide to use Board in the Tile.h file I will use forward referencing (@class Board;), as a few of you suggested.</p> <p>Thanks again!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload