Technically yes, but that would be extremely ugly and could break some other parts of Objective-C.
Objective-C, like C ++, started working as a preprocessor. One of the advantages of this is that each Objective-C method is also displayed as a C function call, which takes an object instance and a method selector as the first two arguments, respectively, and then the other declared arguments in order from left to right.
Both NSObjectand C calls that make up the Objective-C runtime can search for the current C function that will be called to invoke the method.
That way, you could create a C ++ class that grabbed all the C function pointers (it could even do this from the C runtime, making it pure C ++ code, not Objective-C ++), and immediately jumped to the corresponding code like this.
: Objective-C (.. C ), , , , . C, - , , . , .
, ++ Objective-C ++ , .
class MTLArray {
id m_instance;
static NSUInteger (* s_arrayLength)(id object, SEL selector);
};
MTLArray::MTLArray() {
m_instance = [MTLArray new];
if(!s_arrayLength) {
s_arrayLength = [MTLArray instanceMethodForSelector:@selector(arrayLength)];
}
}
NSUInteger MTLArray::getArrayLength() {
return s_arrayLength(m_instance, @selector(arrayLength));
}
... +instanceMethodForSelector: , , . typedef , .