Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 24, 2009, 06:55 AM   #1
Sendel
macrumors newbie
 
Join Date: Feb 2009
preprocessor marcros : How to override NSLog ?

Hi,

i simply want to override the NSLog function when I generate the RELEASE version of an iPhone app.

so it should look like this :

#if DEBUG
#define MyLog (x) NSLog(x)
#else
#define MyLog (x) ;
#endif

but it does not work, seems you cannot use parameters in preprocessor macros like you can do in c/c++ ?

If you have annother more effective solution to override NSLog, that would help me, too.

thank you in advance.
Sendel is offline   0 Reply With Quote
Old Feb 24, 2009, 07:03 AM   #2
pilotError
macrumors 68020
 
pilotError's Avatar
 
Join Date: Apr 2006
Location: Long Island
shouldn't it be #ifdef DEBUG
pilotError is offline   0 Reply With Quote
Old Feb 24, 2009, 07:08 AM   #3
Sendel
Thread Starter
macrumors newbie
 
Join Date: Feb 2009
the line :

Code:
#define ALog(X)  NSLog(X)
is causing the error. Actually there is no #ifdef #else #endif in my code yet. All I tried was to replace the name NSLog by ALog, which does fine with :
Code:
#define ALog  NSLog
but then I cannot override the function with :
Code:
#define ALog(X)  ;
the whole idea is to use everywhere
Code:
..
ALog(@"Name=%@", name);
..
and then replaces it to :
Code:
..
;
..
may be there is another way to tell NSLog to turn off its functionality ?

Last edited by Sendel; Feb 24, 2009 at 07:15 AM.
Sendel is offline   0 Reply With Quote
Old Feb 24, 2009, 07:24 AM   #4
Sendel
Thread Starter
macrumors newbie
 
Join Date: Feb 2009
One Solution could be :

this works for me now:


PHP Code:
#ifdef DEBUG
#define ALog NSLog
#else
#define ALog //NSLog
#endif 

if I keep care of not to add another command to the same line it would comment out the NSLog like

CODE :
PHP Code:
ALog(@"Count = %i"count); [self dont:@"this is no good."]; 

RELEASE :
PHP Code:
// NSLog(@"Count = %i", count); [self dont:@"this is no good."]; 

DEBUG :
PHP Code:
NSLog(@"Count = %i"count); [self dont:@"this is no good."]; 
Sendel is offline   0 Reply With Quote
Old Feb 24, 2009, 08:42 AM   #5
Sendel
Thread Starter
macrumors newbie
 
Join Date: Feb 2009
Ultimative Solution

#if DEBUG
#define ALog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
#define MARK ALog(@"%s", __PRETTY_FUNCTION__);
#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; ALog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
#else
#define ALog(format, ...)
#define MARK
#define START_TIMER
#define END_TIMER(msg)
#endif
Sendel is offline   0 Reply With Quote
Old Feb 24, 2009, 09:48 AM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by Sendel View Post
...seems you cannot use parameters in preprocessor macros like you can do in c/c++ ?
Quote:
Originally Posted by Sendel View Post
#define ALog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
See, you can use parameters with preprocessor macros with Objective-C. You just have to be careful how you use it. I think your problem was you were trying to define it on a method that takes a variable number of arguments. For example,
Code:
#define SQUARE(x) ( (x) * (x) )
is perfectly legitimate. (Tip o' the hat to Stephen Kochan for this example).
dejo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: NSLog to Serial port? xArtx iPhone/iPad Programming 11 Oct 17, 2013 10:03 PM
Apps can override Notification approval? iSensei iOS 6 4 Dec 22, 2012 03:16 AM
Disable NSLog spilakalb iPhone/iPad Programming 3 Oct 1, 2012 03:16 PM
AT&T - Upgrade override Valis33 iPhone 21 Sep 19, 2012 07:44 AM
Any NSlog configuration possible? xArtx iPhone/iPad Programming 5 Jul 5, 2012 01:50 AM

Forum Jump

All times are GMT -5. The time now is 09:50 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC