1

I am creating a listener application that attaches to my app and prints to the console, Variable: "name" when the user taps on a certain component, such as Variable: button if the user taps on a UIButton with the title "button".

I am stuck on UIImagePickerControllers. Does anyone know how to get the variable name, ie, the name used to created the UIImagePicker (UIImagePickerController *imagePicker) if I have that stored as a "self" variable.

Such as, when I do NSLog(@"%@", self); it prints "<UIImagePickerController: 0x8342700>"

How can I get it to print imagePicker, (the variable name)?

Thanks in advance.

Dummy Code
  • 1,858
  • 4
  • 19
  • 38

1 Answers1

2

Inspired from this answer

#define NSLogVariable(x) NSLog( @"Variable : %s",#x)

From code

NSLogVariable(imagePicker);
Community
  • 1
  • 1
Anupdas
  • 10,211
  • 2
  • 35
  • 60
  • This won't work because when I call it, I am using the "self" variable. So when I do NSLogVariable(self); It prints: Variable: self – Dummy Code May 31 '13 at 16:29
  • When you are giving self, the variable name is "self". Waiting for a proper answer. – Anupdas May 31 '13 at 16:34
  • But self is, , and in my native app "self" is declared as UIImagePickerController *imagePicker; – Dummy Code May 31 '13 at 16:35
  • 1
    I don't know how it will resolve variable name "imagePicker" as the memory of the object pickerController can be pointed by any number of variables. – Anupdas May 31 '13 at 16:38
  • Henry, self is a special variable passed into call Objective-C methods referring to the object that owns it. It isn't declared as anything special, other than id self in the method arguments. You don't see this argument as they are automatically added by the compiler for you. Another such special variable is the _cmd variable, which is also added to your method arguments automatically. – Tom Hancocks May 31 '13 at 23:27