Search code examples
objective-ccattributesintrospection

Is there any way to mark up a c function or obj-c method to identify it at runtime?


I'm looking for something similar to attributes in Java, to use in an objective-c environment.

Suppose I have an implementation file with a bunch of methods defined. Is there any way I can mark them up such that I could find them with introspection at runtime? Something like;

##special_method
- (void)foo
{

}

##special_method
- (void)bar
{

}

// Not special
- (void)baz
{

}

As far as I know, nothing exists, and so the best idea I have is to prefix the method name with something common:

- (void)_special_foo
{

}

- (void)_special_bar
{

}

// Not special
- (void)baz
{

}

any other interesting ideas?


Solution

  • I'm not sure if I understand your question correctly, but as an "interesting" possible solution, you can use a global variable that is set to a unique value identifying a specific function on entry (and optionally resetting on exit), or you can use a stack to trace these values that you can inspect at any time.