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.
Asked
Active
Viewed 341 times
3
1 Answers
2
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

wattson12
- 11,176
- 2
- 32
- 34
-
Can I invoke the above like mylog(test); – Warrior Dec 20 '12 at 09:50
-
if you #define the same as my example, doing `MyLogsCalled(@"test");` would be the same as calling `[MyLogs myLogsCalled:@"test"];` so if you had a #define in the same format called mylog then yes – wattson12 Dec 20 '12 at 10:10