What is the objc_selector implementation?

ios, macos, objective-c, objective-c-runtime, selector

Solution

This might help you:

Now this one is fun and interesting. SEL is the type of a "selector" which identifies the name of a method (not the implementation). So, for example, the methods `-[Foo count]` and `-[Bar count]` both share a selector, namely the selector `"count"`. A SEL is a pointer to a struct `objc_selector`, but what the heck is an `objc_selector`? Well, it's defined differently depending on if you're using the GNU Objective-C runtime, or the NeXT Objective-C Runtime (like Mac OS X). Well, it ends up that Mac OS X maps SELs to simple `C strings`. For example, if we define a Foo class with a `- (int)blah method`, the code `NSLog(@"SEL = %s", @selector(blah));` would output `SEL = blah.`

Taken from: here

Problem

I've found that the `SEL` type has the next definition: ``` typedef struct objc_selector *SEL; ``` But I can't find how is `objc_selector` implemented. Okay, if we have the next code ``` #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { SEL mySelector = NSSelectorFromString(@"mySelector"); return 0; } ``` , then `mySelector` is just a pointer. Following the address which it contains, we see the C-string, which can be presented like: ``` const char* mySelector = "mySelector"; ``` But `objc_selector` is not a C-string, it is structure and it can contain something else. So I want to know how `objc_selector` structure is implemented.

Original source

Related problems