ios - How to get an "extern const int" value by its name -


i int value of extern const name.

for example in .h file:

extern const int my_int_const; 

in .m file:

const int my_int_const = 0; 

what want:

- (void) method {     int = [getmyconstantfromstring:@"my_int_const"]; } 

how can that?

i searched in runtime api , did not find anything.

there's no simple way this. neither language nor runtime provide facility this.

it can done using api of dynamic loader symbol's address name.

// near top of file #include <dlfcn.h>  // elsewhere int* pointer = dlsym(rtld_self, "my_int_const"); if (pointer) {     int value = *pointer;     // use value... } 

note, that's c-style string that's passed dlsym(). if have nsstring, can use -utf8string c-style string.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -