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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:57:13+00:00 2026-05-18T03:57:13+00:00

In my project I have 3 classes, let’s call them Apple, Orange and Pear.

  • 0

In my project I have 3 classes, let’s call them Apple, Orange and Pear.

Apple and Orange both have delegate properties.
They both define protocols in their header file called AppleDelegate and OrangeDelegate.
They each have initializers with similar signatures:

- (id)initWithDelegate:(id<AppleDelegate>)delegate
- (id)initWithDelegate:(id<OrangeDelegate>)delegate

Pear implements OrangeDelegate and is defined as follows:

@interface Pear : NSObject <OrangeDelegate>

Inside Pear, I make this call:

Orange *anOrange = [[[Orange alloc] initWithDelegate:self] autorelease];

That results in this compiler warning:

Class 'Pear' does not implement the 'AppleDelegate' protocol

It appears to me that the compiler does not recognize the protocols in the initializers. In other words, it only recognizes this signature for both:

- (id)initWithDelegate:(id)delegate

Because when I click “Jump To Definition” on the initializer in Pear, it brings up both classes as options.

Is there any way to correct this warning aside from renaming my methods?

  • 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-18T03:57:13+00:00Added an answer on May 18, 2026 at 3:57 am

    The problem is that ‘alloc’ is a method inherited from NSObject, defined to return type ‘id’. So the following:

    [Orange alloc]
    

    Evaluates to an object of type ‘id’. When you then call initWithDelegate on that object, the compiler doesn’t know the type and in this case guesses the incorrect one. So you can eliminate the warning with:

    Orange *anOrange = [[(Orange *)[Orange alloc] initWithDelegate:self] autorelease];
    

    So, basically, it’s because constructors aren’t a language level feature in Objective-C, merely a convention.

    EDIT: see below; I guess another solution would be to add:

    + (Orange *)alloc;
    

    To Orange, which would be nothing more complicated than:

    + (Orange *)alloc
    {
        return [super alloc];
    }
    

    I guess it is partly a design decision — should classes be responsible for knowing that their constructor methods may clash with the names of other classes or should files that import multiple class definitions with the same constructors be responsible for disambiguating. Though the simple look of the syntax may be the clincher.

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

Sidebar

Related Questions

Ok, I have an application that I have developed, let's call it Project A.
In my project I have put all my css classes in the style sheets.
In my project I have a class that is inherited by many other classes.
I have a project with a number of different classes querying and modifying data
I have an Xcode project with the following group structure: ProjectName/ Classes/ class1.h class1.m
I have been assigned a project to develop a set of classes that act
I have a generic class in my project with derived classes. public class GenericClass<T>
I am writing helper classes for a large project in PHP and I have
I'm starting a Python project and expect to have 20 or more classes in
Let's say you have 2 totally separate projects: Project 1 and Project 2. One

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.