Get the compilation name of the class, for example __PRETTY_FUNCTION__ and __LINE__

Like

@interface MyClass : NSObject
@end

@implementation MyClass

+ (void)helloWorld 
{
    printf("Hello world. The method being called is %s\n", __PRETTY_FUNCTION__);
}

@end

int main(int argc, char *argv[]) {
    @autoreleasepool {
        [MyClass helloWorld];   
    }
}

Results in

Hello world. The method being called is +[MyClass helloWorld]

I would like to get just the compilation time of the class name.

+4
source share
1 answer

There are no standard tools to get the class name at compile time. Adding such custom behavior is not likely to be difficult, but will require adding custom code to your compiler. Finding where FUNCTION is defined is likely to be a good starting point.

When looking for a very specific type of solution, such as in this case, it is usually best to mention before the problem you want to solve, instead of determining the conditions for your desired solution.

, , , , , , , . , , , , , ( , - , , , , ), , , , , . , , , , , , , , . , , , , ( , , ObjC ) ( ).

+4

All Articles