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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:58:39+00:00 2026-06-12T17:58:39+00:00

I have a protocolA in its own header file, that serves as an interface.

  • 0

I have a protocolA in its own header file, that serves as an interface.
Then I have two concrete classes that are different implementations of that protocol.

Now, in my ViewController, I use this for declaring a property of type id , and it allows me to swap implementations without VC knowing anything about this.

I also have protocolB, that serves for delegate calls from those two implementation objects to the VC.

The problem is I have circular dependency.

In protocol A, i need to declare a “delegate” property of type id.
In protocol B, the delegate methods are sending reference to the caller which is an object of type id…

Is there a better design?


UPDATE with example, maybe it will be helpful for others.

ProtocolA header:

#import <Foundation/Foundation.h>

 /*!
 Abstract interface for any Provider 
 */

@protocol DataProviderDatasource <NSObject>

@required
@property (nonatomic) id <DataProviderDelegate> delegate; 
-(void)update;

@end

ProtocolB header

#import <Foundation/Foundation.h>
#import "DataProviderDatasource.h"
/*!
 Protocol that each  Data Provider implements to make delegate calls to notify its     delegate about data management operations.
 */

@protocol DataProviderDelegate <NSObject>

-(void)dataProviderWillUpdate:(id<DataProviderDatasource>)dataProvider;
-(void)dataProviderdidUpdate:(id<DataProviderDatasource>)dataProvider;

@end

  • 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-12T17:58:40+00:00Added an answer on June 12, 2026 at 5:58 pm

    like classes, you can forward declare protocols:

    @protocol MONProtocolB; // << forward declaration -- #import not required
    
    @protocol MONProtocolA
    - (void)setDensity:(NSValue<MONProtocolB>*)pValue;
                               ^^^^^^^^^^^^ << compiler recognizes this as an
                                               objc protocol
    @end
    

    then the compiler won’t barf when it sees the protocol name and circular dependence is broken (unless your protocols both derive from another which is of course silly).

    you can then #import MONProtocolB wherever there is physical dependence.

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

Sidebar

Related Questions

If I have a delegate which resides within its own header file myDelegate.h. Then
I have the following classes/protocols: @interface Super @end @implementation Super @end @interface Sub1 @end
I currently have a url that looks like this: protocol://folder/file.js I can open this
Imagine I have two protocols: @protocol A @end and @protocol B <A> // Protocol
I'm using twisted. I have my protocols set up so that, to send an
I have a class that executes the MSNP15 protocol. The protocol requires clients to
Many network protocols have their own rfc(request for comment), like this one for http/1.1:
I have started writing my own WebDAV server class in .NET, and the first
I have defined a protocol that all my plug-ins must implement. I would also
I have an application which uses SslStream to send and receive data with its

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.