I have some code in a project which should never be used in the release build, but is useful when testing. I'd like to do something like this:
#ifdef DEBUG
// Run my debugging only code
#endif
Where do I add the DEBUG setting in Xcode 4? I tried putting it in the "Edit Scheme" under Run MyApp->Arguments Passed On Launch, but it didn't work. Alternatively, is there a flag already available for this?
In recent Xcode project templates there’s already a DEBUG=1 macro defined for the Debug build configuration (in the Preprocessor Macros section). You can test it using the #if preprocessor directive.
I usually add my -DDEBUG=1 to the OTHER_C_FLAGS section in my XCode 4 project's build settings.
And yes, they can even discriminate between Debug / Release / ADHOC / Store builds.
Related
I am using this command to build my solution using x64 Native Tools Command Prompt for VS2022:
devenv D:\Dev\Projects\wscc.sln /build "Release|x86"
How do I disable / suppress warnings being output in the console?
I define Unused local variable in my vb project in VS 2022 for test and it outputs the warning 42024 in my console after building with devenv solution.sln /build Release as shown in the picture below.
From devenv doc, there’s no supported parameter like NoWarn to suppress warnings .But i find here’re 2 workarounds to disable / suppress warnings being output in the console.
1 The Compile tab of the Project Designer page allows you to turn warnings on and off. Select the Disable All Warnings check box to disable all warnings .Path:right click project and select Properties.
Or you can select specified waring type(e.g: Unused local variable) and set it to None that will disable Unused local variable warning being output in console. For more information, please refer to doc
Or In Solution Explorer, open the right-click or shortcut menu for the project, and then choose Edit .vbproj. add one or more warning numbers as the value of the element.
For example(with two compiler warnings suppressed)
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>42022,42024 </NoWarn>
</PropertyGroup>
2 use -nowarn For example: The following code compiles Program.vb and does not display any warnings.
I just installed from pkg the SDK 3.7 for Facebook.
I see that I need to put there a value for FacebookAppId. However I have 2 apps: one for testing and one for production.
Since I need to support variables for Debug and Release, I am using an Environment file which determines the value based on the configuration value. (Debug or Release)
How can I "tell" the SDK to use the relevant one for each release type, without changing it manually when building it?
I didn't check in the source code. Just the compiled one.
Is there a way to do it?
You can use the Preprocessor macros over here..
How to use it :
Go to Build settings of your project.
Search "Preprocessor macros". Here define your macros like for eg FBDebugAPPID for debug moed & FBReleaseAPPID for release mode.
FBSettings class used to override the default facebook AppId.
Then after add below code in your delegate method..
#if defined(FBDebugAPPID)
**Use your debug app id**
[FBSettings setDefaultAppID:#"DEBUGAPPId"]
#elif defined(FBReleaseAPPID)
**Use your release app id**
[FBSettings setDefaultAppID:#"RELEASEAPPId"]
#endif
Hope it resolve your problem..
You can change you enviornment.plist variables by adding a run script build phase
To add a Run Script Build Phase in Xcode
Select your application target in your project, then select "Build Phases".
In the menu bar, click "Editor", select "Add Build Phase", and then click on "Add Run Script Build Phase".
You should now see a Run Script section in the middle of your Build Phase options, as shown above.
Inside the body of the Run Script Build Phase, paste in the script.
#!/bin/bash
if [ "${CONFIGURATION}" = "Release" ]; then
/usr/libexec/PlistBuddy -c "Set :FacebookAppID 321" "$INFOPLIST_FILE"
else
/usr/libexec/PlistBuddy -c "Set :FacebookAppID 321" "$INFOPLIST_FILE"
fi
Here's a simpler approach,
Recent Xcode project templates already have a DEBUG=1 macro defined for the Debug build configuration.
You can use it in combination with #ifdef
#ifdef DEBUG
#define FACEBOOK_APP_ID #"FB_DEVELOPMENT_ID"
#else
#define FACEBOOK_APP_ID #"FB_PRODUCTION_ID"
#endif
I have the following scenario:
A Jenkins server which builds my iOS XCode project
The application sources data from a URL that needs to point to a different location depending on whether the build is for production or development
I need to be able to specify, at build-time, which environment I want to build the application for such that the URL used in the code (re: #define DATA_URL #"http://...") is proper for the environment being built for.
I do something simpler and to do this we set a macro in the build-settings under the header Preprocessor Macros then for each type of build (DEBUG, RELEASE, etc) set something like (DEBUG) APP_CONFIG=1 and for (RELEASE) APP_CONFIG=2 and so on for any others you have. Then in your ***-Prefix.pch you can do something like (Note this doesn't have to go in ***-Prefix.pch it can go anywhere in your code)
#if(APP_CONFIG==1)
#define DATA_URL #"http://..."
#else
#define DATA_URL #"http://..."
#endif
I asked something simpler a while a go here is the link Settings bundle for iPhone app
Hope this helps if it is not what you were looking for comment and I will try to amend best to help.
been researching this a while and not sure entirely what to do.
I want to allow users to switch debug mode either on or off. With debug mode on NSLogs will be printed to console.
currently I can set debug mode on or off in the build settings using a preprocessor (DEBUG) and I use the following code to "block" NSLogs.
#ifdef DEBUG
NSLog(#"If you can see this then debug is on");
#endif
I have created a toggle switch in the settings page to get input from the user but I don't know how to use this input to then undefined/redefine DEBUG. Any ideas?
I am not sure if this is even possible so any alternate solutions would also be appreciated.
Many Thanks :)
You should not use preprocessor directives: using #ifdef DEBUG means that, if DEBUG is not defined, that piece of code doesn't get compiled at all.
You should instead replace preprocessor directives with a simple if statement that check a global variable (or, at least, that may be a solution).
I believe your code block would only check if you are building for debug or release and will build accordingly.
You can build it on a device it will be on release mode , I don't think it is possible to run the simulator in release mode otherwise.
Maybe manually building the application for simulator and moving the packed file to run only on simulator without running xcode, but it will not be reasonable I guess.
I want my XCode Objective-C project to be able to detect which configuration it is being built with. How can I achieve this?
You can have per-configuration macro definitions. Open up your project settings, select your configuration from the Configuration drop-down menu, and go to Preprocessor Macros. For Debug, I recommend defining the macro _DEBUG, and for release I recommend defining _RELEASE, as these are the typical ones which are used. These are passed on to the compiler as -D options, e.g. -D_DEBUG.
You can also put -D options directly into the Other C Flags setting.