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)?
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.
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 ( ; ).
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.
get() is an inbuilt method in Java and is used to return the element at a given index from the specified Array.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With