Hi, everybody.
NSProtocolChecker instances don't forward the messages that are in
it's protocol. Here is NSProtocolChecker's forwarding method:
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
unsigned int length;
void *buffer;
if ((struct objc_method_description *)NULL
!= [self methodDescriptionForSelector: [anInvocation selector]])
[[NSException exceptionWithName: NSInvalidArgumentException
reason: @"Method not declared in current protocol"
userInfo: nil] raise];
[anInvocation invokeWithTarget: _myTarget];
length = [[anInvocation methodSignature] methodReturnLength];
buffer = (void *)malloc(length);
[anInvocation getReturnValue: buffer];
if (0 == strcmp([[anInvocation methodSignature] methodReturnType],
[[anInvocation methodSignatureForSelector:
@selector(init: )] methodReturnType]) )
{
if (((id)buffer) == _myTarget)
{
buffer = self;
[anInvocation setReturnValue: buffer];
}
}
return;
}
Notice that the comparison symbol in the protocol check is wrong, it
should be '=='. Besides that, there is something wrong with the
condition in the second 'if', because the former segfaults. What is
the correct condition?