当一个对象调用另一个对象的方法时,Objective-C 使用复杂的消息传递系统。我想知道是否有可能在被调用的方法中确定调用对象是什么?
例如:
@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
为了使断言在执行时通过,我可以在注释行中写些什么performTest
?