Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define a custom keyword in ios programmatically

I want to create a custom keyword programmatically in iphone. For ex. NSLog prints the log in the console. There are my many frameworks that use their own logs (custom logs)like Aphlogs etc. I want to define my own keyword such as MYLogs such that when i use anywhere as MYLogs(stackoverflow); it should call a method "MYLogsCalled" with "stackoverflow" as parameter and i can perform my own actions in that method.

like image 678
Warrior Avatar asked Dec 02 '25 09:12

Warrior


1 Answers

you can use a macro to do this quickly.

first create the method you want to call, so make a class called MyLogs and add a method

+ (void)myLogsCalled:(id)arg; //do whatever you want in the implementation

then define a macro

#define MyLogsCalled(arg) [MyLogs myLogsCalled:arg]

the other way is to define an extern function which handles the logs (this is what NSLog does), but using #defines makes it cleaner to do things like turn off logs in release builds like DLog typically does

like image 155
wattson12 Avatar answered Dec 03 '25 23:12

wattson12



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!