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 4622834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:53:58+00:00 2026-05-22T02:53:58+00:00

Say class A depends on Class B and via versa. So obviously in a.h

  • 0

Say class A depends on Class B and via versa.

So obviously in a.h I would put #import”b.h” and in “b.h” I would import “a.h”

After that

Should we

declare @class A

in b.h AND @class B in a.h

Should we do both or should we use @class only once?

Why?

I reasoned that if I do it only once, say including @class B in a.h, given that a.h also contains #import “b.h” then the class a.h already knows about b.h

However it seems that I got to do it both in xcode and I wonder why.

  • 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-22T02:53:59+00:00Added an answer on May 22, 2026 at 2:53 am

    There’s nothing wrong with using a forward declaration (i.e. @class Foo) in the header file for each class. You can do that if all you need is for each class to reference the other. A forward declaration just tells the compiler “This name refers to a class, and the actual declaration of the class will come later.”

    As you say, you could also use a forward declaration of B in A.h, and then just import A.h in B.h. I don’t think there’s any real benefit to doing that unless there are other things in A.h that you also need to reference in B.h.

    However it seems that I got to do it
    both in xcode and I wonder why.

    If you mean that you’re getting an error when you import A.h in B.h instead of using a forward declaration of A, please post the error. I don’t think there should be a problem with that. (And in any case, the issue would be a compiler issue or an Objective-C issue, not an Xcode problem. Xcode is just the IDE.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains a dynamically allocated array, say class A {
If I have class B : A {} I say that Class B inherited
I'm creating a class (say, C) that associates data (say, D) with an object
Let's say that I want a class that represents a data structure in memory.
I want to create a controller that depends on the class of a given
Say I have: class A depends on class B depends on class C depends
Lets say I have Class A, that calls static methods in either Class B
Say a class Person +Name: string +Contacts: List<Person> I want to be able to
I have a custom class say 'MyCanvas' derived from wpf Canvas class. MyCanvas has
ActionScript 3 / Flex 3 - Adding custom events to a class Say I

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.