How to use code inside #ifdef SHOUTCAST_METADATA - iphone

I am using code of "Matt Gallagher" for streaming player
and there are some code inside
#ifdef SHOUTCAST_METADATA
//Code
#endif
The system is not able to go inside these blocks.
Now currently the code inside is not working.....the code just needed to get the name of the stream playing.
Please help

Add this at the top of the file w/that #ifdef:
#define SHOUTCAST_METADATA 1
Of course, you'll need to deal with any dependencies incurred; that code was compiled out for a reason.

Related

Set DEBUG to false

I want to test the below lines of code :
#ifdef DEBUG
#define VAR 10
#else
#define VAR 20
#endif
In project->build settings->preprocessor macros I had DEBUG=1 and NSLogging the value of VAR logged 10. Then I set DEBUG=0 to check if it loggs 20. But it logged 10 only.How to set DEBUG value so that else condition in code is satisfied?
Just make it easy:
#define DEBUG 1
#ifdef DEBUG
#define debug(...) NSLog(__VA_ARGS__)
#else
#define debug(...)
#endif
When you summit to appstore, comment #define DEBUG 1 :D
This is the way I used.
I dont know how to define something like you but it's great if it's possible!
Could you show me how to do that?
You should NOT be setting DEBUG=0 to get the right result.
Just don't define DEBUG at all to get release behavior.
Remember, #ifdef DEBUG code checks if DEBUG is defined or not.
Alternatively, #if DEBUG code would get you the right result.
As Aditya said, other library used in application may have defined DEBUG macro and hence even I remove it from preprocessor macro the condition #ifdef DEBUG is always satisfied. The solution is simple though. Just use different macro name such as IS_DEBUG instead of DEBUG. This solved my problem. It was a matter of just a macro name.

Is there any way to clear NSLog Output?

I have been googling from last couple of hours for finding that is there any way to clear NSLog output using code or not?
Like we have clrscr() in c. So if we are trying to print something which we want to focus most and there is lots of log printin there we can put that code there and get keep our desire log on top for easy searching. This can be done by putting breakpoint on my NSLog line and than click on clear console. but question is is there a way to achive this programatically?
I found few question on stack overflow but I din't satisfied with answer like this is saying that I can disable log for release mode etc.
Or I can use DLog, ALog or ULog as requirement but my question is different..
Any one can help me in this?
Thanks in advance :)
You can use a conditional breakpoint to simulate it. Define a function like this in your code:
int clear_console()
{
NSLog(#"\n\n\n\n\n\n\n\n");
}
Then, when you want to clear the console just add a breakpoint before the NSLog with this condition:
Condition: 1 > 0
Action: Debugger Command expr (int) clear_console()
Options: Automatically continue after evaluating Check it to skip the pause.
Tested with Xcode 4.3.2 and lldb.
Previous answer:
AFAIK, no, there isn't.
Just in case you're not doing it yet, you can create custom macros to format the output to highlight what you want.
Define macros like this:
#define CLEAR(...) NSLog(#"\n\n\n\n\n\n") /* enough \n to "clear" the console */
#define WTF(...) CLEAR();NSLog(#"!!!!!!!!!!!!!!");NSLog(__VA_ARGS__)
#define TRACE(__message__) NSLog(#">>>>>>>>>>>>>>> %# <<<<<<<<<<<<<<<<<<<", __message__)
Then:
WTF(#"This should't be here object: %#", theObject);
...
TRACE(#"Start Encoding");
...
It's not what you want but it pretty much solves the problem. You'll end up with your own set of macros with custom prefixes easily scannable in the console output.

Lua: require() not working on iPhone

I am working on a shooting game on iPhone and I need lua for scripting levels, enemies, and etc.
So I wrote a bullet script like this:
-- circular_bullet.lua
local time_between_bullets = 0.2;
...
function InitializeCircularBullet(objectName)
...
end
and an enemy script:
-- level1_D2.lua
require("circular_bullet.lua");
...
But it turned out that the enemy script can't "require" the bullet script.
I tried to look into lua library, and found out that in loadlib.c :
static int ll_require (lua_State *L) {
...
if (lua_isfunction(L, -1)) /* did it find module? */
break; /* module loaded sucessfully */
else if (lua_isstring(L, -1)) /* loader returned error message? */
lua_concat(L, 2); /* accumulate it */
else
lua_pop(L, 1);
...
}
It would enter the "else if" branch, which means some error happened, but I have no idea how to read that error message.
If I comment out the "require" line, the enemy "level1_D2" would work as intend without shooting bullet. I also did try copy the whole circular_bullet.lua into level1_D2.lua, and it worked, so the problem must be the require statement.
Those two files are under root directory of the package. (I don't know how to make them in different directory, thus I had found out that Diner Dash kept its scripts in different directory.)
However the two files are not in the same group in my Xcode project. I tried putting them in same group but nothing happened.
Anyone knows what the problem is? Thanks a lot!
Finally I got the answer!!!
the lua require function searches "./scrips" directory for require files, so I got to put those script in the directory!
Yet I still don't know how to change that searching path, but it did work.
I've got a snippet here which might help you to change that path:
// Initialize library path
lua_pushstring(L,"package");
lua_gettable(L, LUA_GLOBALSINDEX);
string path = string(Globals::GetPathPrefix())+"?.lua";
lua_pushstring(L, "path");
lua_pushstring(L, path.c_str());
lua_settable(L, -3);
lua_pop(L,1);
I also had this when I was new to Lua. I don't know this also appears on iPhone, but on Windows I had to remove the '.lua' So just remove the extension.

Suppressing NSLog statements for release? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Do I need to disable NSLog before release Application?
I wonder if someone could help me setup a number of NSLog statements so they print to console when executing in "Debug Mode" but don't print in "Release Mode". I understand I need to add something like DEBUG = 1 to the debug config in Xcode but I can't find where. Also how do I utilise this in my code?
NSLog(#"Print Always");
if(DEBUG) NSLog(#"Print only in debug");
Is there a simple way of doing this?
EDIT_001:
I tried following this but the keys now seem to be only listed under "All Settings", and are presenting as nice names. The one I should be using is GCC_PREPROCESSOR_DEFINITIONS, so I needed to find "Preprocessor Macros", select edit and add DEBUG=1
When you come to use this its simply a case of adding (see below) or some marco to remove the messy #ifdef / #endif tags.
NSLog(#"You always see me?");
#ifdef DEBUG
NSLog(#"Only in DEBUG");
#endif
This is a popular solution:
http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog
See comments about using either -DDEBUG=1 or DEBUG=1.
The best solution is not to use NSLog in the first place but instead rely on the debugger.
You can set breakpoints that execute debugger commands to print out anything and you can set the breakpoints to execute the debugger commands but not to stop execution. In practice this works just like NSLog.
By using the debugger to do the logging, you don't have to worry about removing the log statements.
Please have a look at the answers of How to print out the method name and line number and conditionally disable NSLog?. There are some nice macros in there that can be very useful.
I use this:
-(void)debugWinLog
{
NSUserDefaults * defaultsDebug = [NSUserDefaults standardUserDefaults];
theDebugWin = [defaultsDebug boolForKey:#"logger"];
}
Which is called in the awakeFromNib.
It checks the apps plist file for a 1 or 0 for the BOOL entry "logger"
The normal state if off, but when debugging you can then turn it on or off at will in terminal. with the normal defaults write.
The NSlog statments look like:
if ( theDebugWin) {NSLog (#"%#", windowState );}

How do I check the TARGET_NAME of my iPhone app on XCode?

I'm trying to have 2 version of my iPhone application within the same XCode project.
The codebase it's almost the same and where I need to have different behaviours I've decided to use preprocessor's conditionals and the ${TARGET_NAME} tag.
I've set the OTHER_CFLAGS to contain "-DTARGET_NAME=${TARGET_NAME}".
Then in my code I tried to do
#if TARGET_NAME == myApp
NSLog(#"pro");
#elif TARGET_NAME == myAppLite
NSLog(#"lite");
#endif
Unfortunately I always get "lite" printed out since TARGET_NAME == myApp it's always true: since TARGET_NAME is defined. I cannot for the life of me figure out how to evaluate this string comparison.
Any idea?
thanks in advance
You can't compare strings like that in an #if block. Instead, add the defines to each specific target. For instance, on the full version's target, open the Info panel and go to the build tab and add something like FULL_VERSION to the GCC_PREPROCESSOR_DEFINITIONS build setting. Then, for the lite target, enter something like LITE_VERSION. In your code, you can do:
#ifdef FULL_VERSION
NSLog(#"Full");
#else
NSLog(#"Lite");
#endif
Actually you can get the target's name to compare it, but this will not skip unnecessary code from other targets at compile time, to do this:
First go to menu Product -> Scheme -> Edit Scheme... (or CMD + <)
Then in the arguments section, add inside environment variables something like:
In your code you can get the target's name as:
NSString *targetName = [[NSProcessInfo processInfo] environment][#"TARGET_NAME"];
NSLog(#"target = %#", targetName); // Will print the target's name
You can compare that string now in runtime.
But following your example: if you want that all the Pro version code to be omitted at compile time. You should do what #jason-coco says. And go to preprocessor macros in build settings, and add $(TARGET_NAME) there:
The code inside the #define will be compiled and executed if my target is "MLBGoldPA"
#if defined MLBGoldPA
NSLog(#"Compiling MLBGoldPA");
#endif
to get your conditional evaluation working, you have to do something like:
#define myApp 1
#define myAppLite 2
beforehand, like in your _Prefix.pch file.