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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:41:00+00:00 2026-06-01T11:41:00+00:00

Imagine I have two protocols: @protocol A @end and @protocol B <A> // Protocol

  • 0

Imagine I have two protocols:

@protocol A
@end

and

@protocol B <A> // Protocol B conforms to protocol A.
@end

And also two variables:

id<A> myVar = nil;

and

id<B> otherVar = //correctly initialized to some class that conforms to <B>;

Then, why can’t I assign ‘otherVar’ to ‘myVar’?

myVar = otherVar; //Warning, sending id<B> to parameter of incompatible type id<A>

Thanks!

  • 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-01T11:41:02+00:00Added an answer on June 1, 2026 at 11:41 am

    Is the protocol’s (B) declaration (not just its forward declaration) visible? And does the declaration precede myVar = otherVar;?

    When the declaration order is correct, clang did not complain.

    To illustrate:

    @protocol A
    @end
    
    @protocol B; // << forward B
    
    void fn() {
        id<A> myVar = nil;
        id<B> otherVar = nil;
        myVar = otherVar; // << warning
    }
    
    // declaration follows use, or is not visible:    
    @protocol B <A>
    @end
    

    whereas the properly ordered version produces no warning:

    @protocol A
    @end
    
    @protocol B <A>
    @end
    
    void fn() {
        id<A> myVar = nil;
        id<B> otherVar = nil;
        myVar = otherVar;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's imagine I have two threads which execute some database-oriented code in thread-specific TransactionScopes
Imagine you have two images A and B, and a third grayscale image T.
Imagine we have two tables in the database, user (FK id_role) and role (PK
Imagine the following situation: I have two branches: DEV and MAIN. I'm working on
Imagine a situation, I have PC with two lan cards, one is connected to
Let's imagine really simple game... We have a labirinth and two players trying to
Imagine I have two (three, four, whatever) tasks that have to run in parallel.
Imagine that we have two tables as follows: Trades ( TradeRef INT NOT NULL,
Let's imagine that we have two arrays: $array_1 = array( '0' => 'zero', '1'
Ok, here is the question. Imagine I have a ModelForm which have only two

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.