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

  • Home
  • SEARCH
  • 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 6880317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:57:30+00:00 2026-05-27T04:57:30+00:00

Possible Duplicate: How can I have references between two classes in Objective-C? Objective-C #import

  • 0

Possible Duplicate:
How can I have references between two classes in Objective-C?
Objective-C #import loop

I’m getting a couple errors in my code and I’m not sure but I think its because I’m #importing an interface inside another interface where I’m #importing the other interface. If I’m confusing you I’ll give you an example.

#import "OneClass.h"

@interface SecondClass : NSObject
{
    OneClass * obj;
}

#import "SecondClass.h"

@interface OneClass : NSObject
{
    SecondClass * obj;
}
  • 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-27T04:57:31+00:00Added an answer on May 27, 2026 at 4:57 am

    Yes, you have a circular import. The problem here is that the second import (the one that re-imports your first header) is basically ignored by the compiler, since it thinks it’s already imported that header.

    The solution here is to use @class forward-declarations instead of using #imports. Not only does this solver the circular import problem, but it’s a better idea anyway since it breaks unnecessary dependency chains (e.g. if I edit OneClass.h, SecondClass.h won’t need to be re-processed).

    To apply this here, simply remove the #import OneClass.h in SecondClass.h and replace it with @class OneClass;

    In the more general case, you don’t ever need to #import a header file just to declare an ivar/property/method that uses a class from that header. The @class token is sufficient. You do, however, need to #import the header file if you’re inheriting from the class, or if you’re referencing another non-class type declared in that header. Also remember that if you use @class in your header, you need to remember to put the actual #import into your .m file.

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

Sidebar

Related Questions

Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicate: Reading dll.config (not app.config!) from a plugin module. I have two different
Possible Duplicate: Self-references in object literal declarations I have an object literal which is
Possible Duplicate: Can I set a breakpoint on 'memory access' in GDB? I have
Possible Duplicate: Learning jQuery and Getting Better at Javascript I have found jQuery very
Possible Duplicate: Can someone explain this template code that gives me the size of
Possible Duplicate: Can I access session state from an HTTPModule? I have set up
Possible Duplicate: Can’t operator == be applied to generic types in C#? I've got
Possible Duplicate: Can’t operator == be applied to generic types in C#? I've coded
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This

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.