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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:19:35+00:00 2026-06-07T09:19:35+00:00

I was building an app when I ran into some errors. After doing some

  • 0

I was building an app when I ran into some errors. After doing some research, I found that the reason is because I am working with 2 files, that each #import each other. I read that the cure to this is to use Forward Declaration, but I couldn’t find a good example of how this is done.

Here is what I have.

RootViewController.h

#import <UIKit/UIKit.h>
#import "FirstDetailViewController.h"

@protocol SubstitutableDetailViewController
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
@end


@interface RootViewController : UITableViewController <UISplitViewControllerDelegate, FirstDetailViewControllerDelegate>{

    UISplitViewController *splitViewController;

    UIPopoverController *popoverController;    
    UIBarButtonItem *rootPopoverButtonItem;

    NSMutableArray *logMessages;
}

@property (nonatomic, assign) IBOutlet UISplitViewController *splitViewController;

@property (nonatomic, retain) UIPopoverController *popoverController;
@property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;

@end

FirstViewDetailController.h

#import <UIKit/UIKit.h>
#import "RootViewController.h

//test2
@protocol FirstDetailViewControllerDelegate <NSObject>
- (void)addItemViewController:(FirstDetailViewController *)controller didFinishEnteringItem:(NSString *)item;
@end
//end test2

@interface FirstDetailViewController : UIViewController <SubstitutableDetailViewController> {

    //for the output
    IBOutlet UITextView *outputView;

    UIToolbar *navigationBar;

}

@property (nonatomic, retain) IBOutlet UIToolbar *navigationBar;

//test
@property(nonatomic, retain) NSString *message;
//end test

@property (nonatomic, retain) id <FirstDetailViewControllerDelegate> delegate;

@end

I know that I need to replace #import with @class, but do I do it for both occurrences? Also, I a already #import "FirstDetailViewController.h" in the RootViewController.m file, so do I switch it there as well ?

I am a little confused so any help would be appreciated !

  • 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-06-07T09:19:37+00:00Added an answer on June 7, 2026 at 9:19 am

    Forward declaration would be the solution if it were just pointers you needed, but you are implementing the other header’s protocol in each class.

    My suggestion would be to declare your protocols in some other header file, such as MyProtocols.h and include that in both of your .h files instead of the controllers’ headers.

    On a side note, having a strong, or retained reference to one’s delegate isn’t really standard practice, as this can easily cause a retain cycle which leads to leaked memory

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

Sidebar

Related Questions

Hey I'm building an app that will allow a user to log into a
Im building an app that takes a photo of the user, its working fine
Building an app with the Facebook JavaScript API that will embedded into a page
While building a Search for my app i ran into a problem whilst using
It seems that the Android SDK doesn't compile my android app correctly. After building
Im building an app which uses Sqlite DB. Users can enter their information into
Currently building an app that runs on mobile phones not related to the issue
I am building an app that performs a lot of client side data downloading
I am building an app that does a lot of math and calculations. I
So I'm building an app that needs to know the location of the Box

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.