I have a preprocessor macro that I use like this:
@implementation MyClass
- (void)methodA
{
MyLog("Hello, method A!");
}
- (void)methodB
{
MyLog("Hello, method %@!", @"B");
}
@end
And after macro expansion it looks like:
@implementation MyClass
- (void)methodA
{
; NSLog([NSString stringWithFormat:@"%s - %@", __func__, "Hello, method A!"]); ;
}
- (void)methodB
{
; NSLog([NSString stringWithFormat:@"%s - %@", __func__, "Hello, method %@!"], @"B"); ;
}
@end
This will result in these being printed for their respective methods:
-[MyClass methodA] - Hello, method A! -[MyClass methodB] - Hello, method B!
I want to change this to a set of Objective-C or Swift methods, which I can call the same way and would give me the same result. I don't want to manage an object, so these should be class/static methods. Is it possible to tell that I'm in a particular class/method and only use a particular log prefix while in there?
If not, is there any other way to use methods to mimic the behavior I achieved with the macros?