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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:05:30+00:00 2026-06-01T16:05:30+00:00

Is there a way to indicate to the compiler that a class object conforms

  • 0

Is there a way to indicate to the compiler that a class object conforms to a protocol?

As I understand, by creating +(void)foo class methods, an instance of that class object will have those methods as instance methods. So, as long as I create +(void)foo methods for all required protocol methods, I can have a class object act as a delegate.

My problem of course is that in the class’s header file, I only know how to indicate that instances of the class conform to the protocol (as is typically the case). So, the best I’ve figured out is to cast the class object like so:

something.delegate = (id<SomethingDelegate>)[self class]

Any ideas?

Related, but different:
ObjC: is there such a thing as a "class protocol"?

  • 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-01T16:05:31+00:00Added an answer on June 1, 2026 at 4:05 pm

    What you’re doing now is correct as it will silence warnings which is your goal. You will be sending the class object messages defined in the protocol for instances which is a bit confusing, but the runtime doesn’t care.

    Think about it this way: you want to set a delegate to an object that responds to the messages defined in the protocol. Your class does this, and your class is also an object. Therefore, you should treat your class like an object that conforms to that protocol. Therefore, what you’ve written is completely correct (based on what you’re trying to do).

    One thing to note, though, is this class will not properly respond to conformsToProtocol:. This is generally okay for a delegate setup anyway (delegates don’t usually check if the class conforms — they just check if it can respond to a selector).

    As a side note, one thing you can do syntactically is:

    Class<SomethingDelegate> variable = (Class<SomethingDelegate>)[self class];
    

    The difference here is that the compiler will use the class methods from the protocol instead of instance messages. This is not what you want in your case, though.

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

Sidebar

Related Questions

Is there any way to indicate to the compiler that you know the value
Is there any way to indicate to ReSharper that a null reference won't occur
In .NET, is there a standard way to indicate that a web service method
Is there a way to indicate that two or more regex phrases can occur
Is there a way to indicate a MSMQ message should not be delivered before
Is there way that I can read the file from remote server using fopen
Is there a way to do the below? Imagine a generic result wrapper class.
I'm trying to do something like this: class foo { virtual void bool operator==(foo
Is there a way to highlight unmatched HTML tags in Notepad++? For instance, if
Is there a way to exclude a processor from normal scheduling? That is, using

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.