Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 376
Egil Avatar asked May 25 '11 06:05

Egil


People also ask

How do you find the method object?

getMethod() returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. The name parameter is a String specifying the simple name of the desired method.

How do you reference a call object in Java?

The dot ( . ) is used to access the object's attributes and methods. To call a method in Java, write the method name followed by a set of parentheses (), followed by a semicolon ( ; ).

How is an object method called?

Calling an object's method is similar to getting an object's variable. To call an object's method, simply append the method name to an object reference with an intervening '. ' (period), and provide any arguments to the method within enclosing parentheses.

Is get a method in Java?

get() is an inbuilt method in Java and is used to return the element at a given index from the specified Array.


1 Answers

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.

like image 68
jscs Avatar answered Nov 16 '22 02:11

jscs