Warrior
Warrior

Reputation: 39374

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.

Upvotes: 3

Views: 386

Answers (1)

wattson12
wattson12

Reputation: 11174

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

Upvotes: 2

Related Questions