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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:27:16+00:00 2026-05-25T17:27:16+00:00

I have the following method: -(void)SomeMethod:(id)classOrProtocol; It will be called like this: [self someMethod:@protocol(SomeProtocol)];

  • 0

I have the following method:

-(void)SomeMethod:(id)classOrProtocol;

It will be called like this:

[self someMethod:@protocol(SomeProtocol)];

Or

[self someMethod:[SomeClass class]];

Within the method body I need to decide if |classOrProtocol| is:

Any Class(Class) OR Any Protocol(Protocol) OR Anything else

[[classOrProtocol class] isKindOfClass: [Protocol class]]

Results in a (build)error:

Receiver ‘Protocol’ is a forward class and corresponding @interface may not exist

So how can I tell a Protocol from a Class from anything else?

  • 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-25T17:27:16+00:00Added an answer on May 25, 2026 at 5:27 pm

    In Objective-C 2 (i.e. unless you use 32 bit runtime on OS X) Protocol is defined to be just a forward class, see /usr/include/objc/runtime.h. The real interface is nowhere declared. You can try to include /usr/inlcude/objc/Protocol.h by saying

    #import <objc/Protocol.h>
    

    but as is written there, no method is publicly supported for an instance of Protocol. The only accepted way to deal with Protocol instances is to use runtime functions, given in Objective-C Runtime Reference. It’s not even publicly defined whether Protocol is a subclass of anything, and it’s not even stated that it implements NSObject protocol. So you can’t call any method on it.

    Of course you can use the source code of the runtime to see what’s going on. Protocol inherits from Object (which is a remnant from pre-OpenStep NeXTSTep), not from NSObject. So you can’t use the familiar methods for NSObject-derived objects, including Class of NSObject-derived objects. See the opensourced implementations of Protocol.h and Protocol.m. As you see there, the class Protocol itself doesn’t do anything, because every method just casts self to protocol_t and calls a function. In fact, as can be seen from the function _read_images and others in objc-runtime-new.mm, the isa pointer of a Protocol object is set by hand when the executable and libraries are loaded, and never used.

    So, don’t try to inspect whether an id is a Protocol or not.

    If you really need to do this, you can use

    id foo=...;
    if(foo->isa==class_getClass("Protocol")){
        ...
    }
    

    But, seriously, don’t do it.

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

Sidebar

Related Questions

I have the following BL method public static void SomeMethod (List<SomeClass> group) { IEnumerable<SomeClass>
Suppose you have a method with the following signature: public void SomeMethod(bool foo =
I have the following class: package x.y.z; public class MyClass{ public void someMethod(SomeObject object){
I have the following method: -(void)testAPIModule { self.requests = [NSMutableArray array]; NSLog(@making arrays); /*(A)*/
I have the following method: public void PutFile(string ID, Stream content) { try {
I have the following method public static void SerializeToXMLFile(Object obj,Type type, string fileName) {
I have the following C++ method : __declspec(dllexport) void __stdcall getDoubles(int *count, double **values);
i have the following method in a usercontrol protected override void Render(HtmlTextWriter writer) {
Hey - I have the following method on my UITableView controller public void RemoveEventFromList(Event
If i have the following method - public static void C() { Connection con

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.