Egil
Egil

Reputation: 4435

Get the object which called a method

If I have a call from within a random class like this:

@implementation SomeClass

- (void) classMethodFoo
{
    int a = [SomeSingleton sharedInstance].aValue;
}

@end

Inside SomeSingleton sharedInstance, is there a way to get a reference to the object which called this method (without the called passing self as a parameter of course)?

Upvotes: 7

Views: 1139

Answers (1)

jscs
jscs

Reputation: 64002

No, information about the caller isn't passed along automatically.

This is why IBAction methods, for instance, have a sender parameter, and why delegate methods often have a parameter that refers to the delegate's object.

Upvotes: 7

Related Questions