What exactly is the DEBUG=1 setting doing in LLVM Build settings? - iphone

When Xcode shows a preprocessor macro of DEBUG=1 in its Build Settings, is this equivalent to typing a preprocessor macro manually, such as #define DEBUG 1 ?

Yes, that corresponds to the "-DDEBUG=1" preprocessor option which is equivalent to a macro definition #define DEBUG 1 that is read before any source file is processed.

Yes, But only in the Debug configuration. If you add #define DEBUG 1 to your code then DEBUG will be defined in both the Release and Debug configurations. Different actions use different build configurations
Action | Configuration
--------------------------
Run | Debug
Test | Debug
Profile | Release
Analyze | Debug
Archive | Release
So by defining DEBUG in the Build Settings you can add code that only runs in your local builds. But not in your Ad Hoc or App store versions.
#ifdef DEBUG
[self.tapGestureRecognizer addTarget:self action:#selector(segueHiddenDevMenu:)];
#endif
This code adds a developer only menu to "Nuke and Pave the Database", "Add 10000 new records to the Database", Create the Default Image View. Stuff the users should not play with. And hidden functionality that would get your app rejected.

Related

WARNING: No screenshots were found for '( locale )' when trying to -exportLocalizations

I have a set of XCUITests that step through a Swift-based application. In the test plan configuration, I've selected to create Localization screenshots for the Dutch language.
When I then try to export the localization from XCode 12.5, I am able to see Dutch as an option and the screenshots export as I would expect.
However, when I attempt to actually export them from the command line (which I need to do in order to embed them in automation), I get an error:
xcodebuild -exportLocalizations -project 'test/test-inhouse.xcodeproj' -localizationPath localizations_output -exportLanguage nl -includeScreenshots
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -exportLocalizations -project test/test-inhouse.xcodeproj -localizationPath localizations_output -exportLanguage nl -includeScreenshots
User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES
--- xcodebuild: WARNING: No screenshots were found for '(
nl
)'
It doesn't matter what spelling I use, or if I put in Dutch. The error is always similar, it can't find the screenshots. I even looked at the project.pbxproj to ensure I'm putting it in exactly as is in the array.
I'm trying to not introduce further dependencies to our CI process, and simply use the built-in XCodeBuild command. Any thoughts on why it can't find the screenshots? Do I have to also specify what device type was built to or something?
It turned out that I was using a project instead of a workspace reference.
From what I can tell, a project is only a single compilable set of code and targets.
Our UITest target is actually a separate compilable object, so when I exported localizations with screenshots for workspace instead of project, it worked.

Environment variables iOS

I come from a Ruby on Rails background, where we have the beautiful Rails.env variable. As a new iOS developer I'm wondering how can I set a development environment variable for an iOS, or where I could find an existing one.
My current method is to use a macro
#define DEVELOPMENT 1
However than I have to manually change this before launching, it doesn't feel clean. I saw that in my build settings there was a slew of environment variables. What is the semantic way to use those to distinguish dev/production?
Your project should already include a DEBUG preprocessor macro (defined as part of the project template). This is defined in the build settings and only set for the Debug build configuration. You can use this setting and define others if required. Then, when you build for Debug / Release the flags will automatically be enabled / disabled.
You use them like:
#ifdef DEBUG
// TEST
#else
// PRODUCTION
#endif

Code Coverage GCov not working with XCode 4.2 and iOS SDK 5

I've been trying to get GCov working with Xcode 4.2Build 4D199 on Lion with iOS SDK 5.0 to no avail. Has anyone had any luck with this? I'm using Google Tools For Mac for my unit tests and I've linked in libprofile_rt.dylib and added:
"OTHER_CFLAGS[arch=*]" = (
"-ftest-coverage",
"-fprofile-arcs",
"-falign-loops=16",
);
as indicated on the Coverstory page here http://code.google.com/p/coverstory/wiki/UsingCoverstory
But when I find . -name *.gcda" I come up empty. What am I missing?
GCov is no longer supported in XCode 4.2. You'll note that if you go their "man page" for it, XCode 4.2 is not an option in the drop down list. Furthermore, if you look at the compile, it's using "c++", which is linked to llvm-g++-4.2. They now exclusively use the Clang/LLVM tool chain (which in turn often makes use of the gcc tool chain) instead of giving you the option of directly using the gcc tool chain. A consequence of this is that doing code coverage in XCode4 with gcov is no longer directly available. This also can affect compiles using CMake that bypass XCode 4. That first link gives you instructions on how to change your project to use profile_rt instead of gcov.
How to generate coverage test reports (Xcode 4.5 edition)
cd to your Xcode project and type
git clone git#github.com:j4n0/XcodeCoverage.git
cd XcodeCoverage
wget http://downloads.sourceforge.net/ltp/lcov-1.10.tar.gz
tar -zxvf lcov-1.10.tar.gz
Set the following build properties on both your main target and your SentestKit target, but only for the Debug configuration (expand the node, there are Debug and Release entries):
Generate Profiling code Yes
Generate Test Coverage Files Yes
Instrument Program Flow Yes
Install Xcode command line tools: Xcode > Preferences > Downloads > Command Line Tools.
In your main target, add a “Run Script” build phase to execute ./XcodeCoverage/exportenv.sh
Build your application, and run the tests.
Generate the coverage report from the XcodeCoverage typing: ./getcov
Upon completion, the script will launch a browser with the html output.
If reports are not generated try this:
Edit the plist of your application and add the following:
<key>UIApplicationExitsOnSuspend</key>
<true/>
Then run your application and press Home. This will quit cleanly and generate the gcda files.
If it still doesn't work, try using the iPad simulator instead.
For more tips and tricks check the talk Code Coverage on iOS by Richard Buckle.

Show or log preprocessor macros during build

Is it possible to log or print preprocessor macros in XCode to the build results?
I want to see the current defined macros during a build.
For example if I have defined DEBUG and TESTSERVER as preprocessor macro there should be some lines in the build results like:
Compile Class.m ....
GenerateDSYMFile .....
Used macros: DEBUG, TESTSERVER...
Maybe there is custom shell script that could be executed after build.
OK I found the solution in the Apple documentation
Just enter a echo $GCC_PREPROCESSOR_DEFINITIONS to the run script build phase.
If you add a Run Script to the build phase and make sure "Show environment variables in build log" is checked it will print out all the environment variables for you. The run script can be empty and you will get a dump of all of the environment variables set for that current build. What you will not get is macros defined in header files.
To access the information once your project is built go to build results and expand the section "Run custom shell script " to view the values.
If you have set up Preprocessor definitions it will show on a line like this
setenv GCC_PREPROCESSOR_DEFINITIONS "DEBUG=1 Debug=1"

Xcode and Generate Debug Symbols

Which setting in Project Settings page needs to be set in order for Xcode to generate debug symbols for a project?
If I set 'Generate Profiling Code" to checked, as soon as I try to build, I get the error,
cc1obj: error: unrecognised debug
output level "-full"
If not, the other way to do this I thought was by setting the 'OTHER_CFLAGS' value to '-g' but it also yields the same error.
Under your compiler's settings group ("i.e. GCC 4.2 - Code Generation") there's a setting called "Generate Debug Symbols".
You can get an overview of probably all debug-related settings just by typing "debug" in the search box.