Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a classic problem with headers importing headers. You have a circle here: Tile.h is importing Board.h, which imports Tile.h. This confuses the compiler -- it gets stuck in a loop.</p> <p>You solve this by not importing headers into headers. You still need to let the compiler know about <code>Tile</code>, however. In Board.h, make a <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocDefiningClasses.html#//apple_ref/doc/uid/TP30001163-CH12-TPXREF124" rel="noreferrer">"forward declaration"</a> of the class:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "cocos2d.h" @class Tile; // Dear compiler, // Tile is a class that I will need to refer // to in this file. Please consider it to be a // type; I promise it'll be defined at runtime. // Sincerely, stephenalexbrowne @interface Board : NSObject //etc. </code></pre> <p>This assures the compiler that there is a class called <code>Tile</code> that will exist at runtime; you can then refer to that name in the remainder of your header. In your implementation for <code>Board</code>, you import Tile.h. That will let the compiler see the methods and properties associated with the <code>Tile</code> class where they are needed. </p> <p>Likewise, move the <code>#import "Board.h"</code> into Tile.m. Since you aren't referring to the <code>Board</code> class in Tile.h, you don't need to make a forward declaration.</p> <p>In general, it is best to import your class headers only into the implementation files where they are needed. Framework headers, since they will never cause a cycle with your code, can and -- because you need to refer to many of the classes declared in them -- should be imported into your headers.</p>
 

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