Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:09:08+00:00 2026-05-28T14:09:08+00:00

I have a basic best-practices question in Objective C. I understand the difference between

  • 0

I have a basic best-practices question in Objective C. I understand the difference between @class and #import but I do not understand why the default Apple Xcode templates do this:

AppDelegate.h:

@class ViewController;

.m:

#import "ViewController.h

When you could instead just put the latter #import in the .h and leave mention of ViewController out of the .m altogether, thereby simplifying by 1 line of code.

Of course, saving 1 line of code is not the issue, I’m just curious why it’s being done this way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:09:08+00:00Added an answer on May 28, 2026 at 2:09 pm

    The line @class ViewController; is a forward declaration so the compiler has an idea what the name ViewController should mean. The point is to try to do as few #import‘s in a header file as possible to speed up compiling.

    Imagine a file a.h which does #import "b.h". Now every file that imports a.h automatically also imports b.h which increases the amount of work the compiler has to do. By using forward declarations one can often avoid such additional imports and thus avoid the additional work for the compiler.

    The bigger the project and the more complex the class hierarchies and dependencies become the more these #imports can become an issue. So it’s a good idea to develop a habit of using forward declarations where possible.

    Edit: After the comments, another important use-case surfaced: to resolve cyclic dependencies. For example, if class A wants to reference class B and vice versa, one has to be defined before the other. But because they need to know the other we have a paradox. It’s solved like this:

    // Tell the compiler: B will be a class type.
    @class B;
    
    // Now we can define A, the compiler has enough
    // information to know what B means.
    @interface A : NSObject {
        B *b;
    }
    @end
    
    // Since A is now defined, we can define B.
    // Cycle is resolved.
    @interface B : NSObject {
        A *a;
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic question about using the Best Practices in coding. (I'm using
I have a basic understanding of mock and fake objects, but I'm not sure
Ok, not really sure how to word, but will try my best. I have
Currently, i have basic C++ and PHP skills. But, i want to switch to
I have a basic cs-major understanding of multi-threading but have never had to do
I have a basic jQuery selector question. Let's say I'm parsing JSON and generating
For a basic app with nonconsumable in-app purchases, has anyone figured out best practices
I know a lot of question regarding VB6 migration have been asked, but I
Had a basic WinForm question: By default a resx file is created for every
This is a rather basic question, but it's one that's bugged me for awhile.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.