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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:38:12+00:00 2026-05-11T16:38:12+00:00

Okay, this might be a very silly beginner question, but: I’ve got an ClassA,

  • 0

Okay, this might be a very silly beginner question, but:

I’ve got an ClassA, which will create an child object from ClassB and assign that to an instance variable. In detail: ClassA will alloc and init ClassB in the designated initializer, and assign that to the childObject instance variable. It’s header looks like this:

#import <Foundation/Foundation.h>
#import "ClassB.h"

@interface ClassA : NSObject {
    ClassB *childObject;
}

@end

Then, there is the header of ClassB. ClassB has to have a reference to ClassA.

#import <Foundation/Foundation.h>
#import "ClassA.h"

@interface ClassB : NSObject {
    ClassA *parentObject;
}

- (id)initWithClassA:(ClassA*)newParentObject;

@end

When the ClassA object creates an child object from ClassB, then the ClassA object will call the designated initializer of the ClassB object, where it has to pass itself (self).

I feel that there is something wrong, but for now I don’t get exactly what it is. One think I know is that this does not work. They can’t bove import eachother. The compiler just tells me: “error: syntax error before ‘ClassA'”. When I remove the import statement for importing ClassA, remove the ClassA *parentObject instance variable and remove the designates initializer (that takes ClassA reference), then it works.

Now, here is what I want to achieve (if this matters): I need some very special and complex behavior in an UIScrollView. So I decided to subclass it. Because the main part is going to be done inside the delegate methods, I decided to create an “generic” delegate object for my subclass of UIScrollView. My UIScrollView subclass then creates automatically that special delegate object and assigns it to its delegate property. The delegate object itself needs a reference to it’s parent, the customized UIScrollView, so that it has access to the subviews of that scroll view. But anyways, even if there’s a better way to get this problem done, I’d still like to know how I could do it that way with two “interdependent” objects that need eachother.

Any suggestions are welcome!

  • 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-11T16:38:12+00:00Added an answer on May 11, 2026 at 4:38 pm

    You don’t need to import those classes in the header files. Use @class in the header files, and then use #import only in the .m files:

    // ClassA.h:
    @class ClassB;
    @interface ClassA : NSObject
    {
        ClassB *childObject;
    }
    @end
    

    // ClassA.m:
    #import "ClassA.h"
    #import "ClassB.h"
    @implementation ClassA
    //..
    @end
    

    // ClassB.h
    @class ClassA;
    @interface ClassB : NSObject
    {
        ClassA *parentObject;
    }
    - (id)initWithClassA:(ClassA*)newParentObject;
    @end
    

    // ClassB.m:
    #import "ClassB.h"
    #import "ClassA.h"
    @implementation ClassB
    //..
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 285k
  • Answers 285k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should have a file called XMLParser.h that includes something… May 13, 2026 at 4:43 pm
  • Editorial Team
    Editorial Team added an answer If you are using Linux, you should use pselect instead… May 13, 2026 at 4:43 pm
  • Editorial Team
    Editorial Team added an answer I've done a few of these "lists" over time and… May 13, 2026 at 4:43 pm

Related Questions

Okay, this might be a very silly beginner question, but: I've got an ClassA,
Start with these simple classes... Let's say I have a simple set of classes
I have a process that's going to initially generate 3-4 million PDF files, and
Okay, this is driving me nuts. I’m working through the IBM CakePHP Tutorial, and
Okay, simple question.. :) In my webportal I got users, who obviously need to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.