Dynamically retrieving current method's name

前端 未结 3 2012
谎友^
谎友^ 2020-12-25 14:56

I\'d like to be able to put trace messages of the current class name and method name for all classes in my project.

Is there a way to get the current method\'s name

相关标签:
3条回答
  • 2020-12-25 15:19
    NSLog(@"method name: %@", NSStringFromSelector(_cmd));
    

    _cmd is a hidden argument (like self) that all Objective-C methods receive. Its value is the selector that was used to call the method.

    0 讨论(0)
  • 2020-12-25 15:36

    This also works:

    NSLog(@"%@", [NSString stringWithUTF8String:__func__])
    
    0 讨论(0)
  • 2020-12-25 15:38

    EDITED: i think this method is more generic...check it out..

    NSLog(@"%s", __PRETTY_FUNCTION__);
    
    0 讨论(0)
提交回复
热议问题