Objective-C uses a sophisticated message-passing system when one object calls a method on another object. I want to know if it is possible, within the called method, to determine what the calling object was?
For example:
@implementation callingClass
- (void)performTest
{
calledObject = [[[calledClass alloc] init] autorelease];
id result = [calledObject calledMethod];
assert(result == this);
}
@end
@implementation calledClass
- (id)calledMethod
{
id objectThatCalledThisMethod = ... // <-- what goes here?
return objectThatCalledThisMethod;
}
@end
What could I write in the commented line in order to make the assertion pass when I execute performTest
?