---
title: "Warning messages of ‘@class Vs. #import’"  
description: "Warning messages of ‘@class Vs. #import’"  
author: "Tarun Kumar"  
published: 2015-09-02  
updated: 2015-09-02  
canonical: https://www.mindstick.com/forum/33433/warning-messages-of-class-vs-import  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Warning messages of ‘@class Vs. #import’

It is to my [understanding](https://www.mindstick.com/articles/12918/cat-5e-vs-cat-6a-understanding-the-major-differences) that one should use a [forward](https://www.mindstick.com/forum/33488/in-webview-disabling-uitoolbar-s-back-and-forward-butttons)-class declaration in the event ClassA needs to include a ClassB [header](https://www.mindstick.com/articles/336036/explain-about-html-header-body-and-footer-tags), and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an [#import](https://www.mindstick.com/interview/2709/what-is-import) is a [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) ifndef so that an include only happens once.

My inquiry is this: When does one use #import and when does one use @class? Sometimes if I use a @class declaration, I see a [common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business) [compiler warning](https://www.mindstick.com/forum/877/simplest-an-fastest-c-sharp-expression-that-always-evaluates-to-false-and-does-not-generate-a-compiler-warning) such as the following:

```
warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.
```

Would really love to understand this, versus just removing the @class forward-declaration and throwing an #import in to silence the warnings the compiler is [giving](https://yourviews.mindstick.com/view/80639/regifting-is-far-better-than-giving-away-a-bouquet) me.

## Replies

### Reply by Anonymous User

If you see this [warning](https://answers.mindstick.com/blog/77/psychological-risks-of-ai-chatbots-what-experts-are-warning-about):\
warning: receiver 'myCoolClass' is a forward class and corresponding @interface may not exist

you need to #import the file, but you can do that in your implementation file (.m), and use the @class declaration in your header file.

@class does not (usually) remove the need to #import files, it just moves the requirement down closer to where the information is useful.

**For Example**\
If you say @class myCoolClass, the [compiler](https://www.mindstick.com/articles/27/just-in-time-compiler) knows that it may see something like:

myCoolClass *myObject;

It doesn't have to worry about anything other than myCoolClass is a valid class, and it should reserve room for a pointer to it (really, just a pointer). Thus, in your header, @class suffices 90% of the time.

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 #import "myCoolClass.h", to tell the compiler additional information beyond just "this is a class".\


---

Original Source: https://www.mindstick.com/forum/33433/warning-messages-of-class-vs-import

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
