Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>"#import"</strong> brings the entire header file in question into the current file; any files that THAT file <strong>#imports</strong> are also included. </p> <p><strong>@class</strong>, on the other hand (when used on a line by itself with some class names), just tells the compiler "Hey, you're going to see a new token soon; it's a class, so treat it that way).</p> <p>This is very useful when you've got the potential for '<strong>circular includes</strong>'; ie, Object1.h makes reference to Object2, and Object2.h makes reference to Object1. If you <code>#import both</code> files into the other, the compiler can get confused as it tries to <code>#import</code> Object1.h, looks in it and sees Object2.h; it tries to <code>#import</code> Object2.h, and sees Object1.h, etc.</p> <p>If, on the other hand, each of those files has <code>@class</code> Object1; or <code>@class</code> Object2;, then there's no circular reference. Just be sure to actually <code>#import</code> the required headers into your implementation (.m) files.</p> <p><strong>For Example</strong></p> <p>If you say <code>@class myClass</code>, the compiler knows that it may see something like:</p> <pre><code>myClass *myObject; </code></pre> <p>It doesn't have to worry about anything other than myClass is a valid class, and it should reserve room for a pointer to it (really, just a pointer). Thus, in your header, <code>@class</code> suffices 90% of the time.</p> <p>However, if you ever need to create or access myObject's members, you'll need to let the compiler know what those methods are. At this point (presumably in your implementation file), you'll need to <code>#import "myClass.h"</code>, to tell the compiler additional information beyond just "this is a class".</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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