Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How to convince my parents to let me buy a 17" MacBook Pro Ulf1103 Buying Tips and Advice 58 Nov 27, 2013 11:45 AM
Tutorial: How to get PCSX2 to run on Mac (without BootCamp) Mirrors Mac Applications and Mac App Store 22 Jun 14, 2013 08:19 PM
IPHONE 4 how to JAILBREAK AND UNLOCK bs2511feist Jailbreaks and iOS Hacks 6 Apr 14, 2012 05:52 PM
Does anybody know how to get TweetTask? xmelissaxmayhem Jailbreaks and iOS Hacks 3 Jul 3, 2011 01:21 AM
[HOW TO] DIY iPhone 4 Swivel Car Mount QuarterSwede iPhone Accessories 13 Mar 8, 2011 02:51 PM


All times are GMT -5. The time now is 11:24 PM.

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

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