What #defines are set up by Xcode when compiling for iPhone

Question!

I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like #ifdef IPHONE_SDK....

Presumably Xcode defines something, but I can't see anything under project properties, and Google isn't much help.



Answers

It's in the SDK docs under "Compiling source code conditionally"

The relevant definitions are TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR, which are defined in /usr/include/TargetConditionals.h within the iOS framework. On earlier versions of the toolchain, you had to write:

#include "TargetConditionals.h"

but this is no longer necessary on the current (xCode 6/iOS8) toolchain.

So, for example, if you want to only compile a block of code if you are building for the device, then you should do

#if !(TARGET_IPHONE_SIMULATOR)
...
#endif


To look at all the defined macros, add this to the "Other C Flags" of your build config:

-g3 -save-temps -dD

You will get some build errors, but the compiler will dump all the defines into .mi files in your project's root directory. You can use grep to look at them, for example:

grep define main.mi

When you're done, don't forget to remove these options from the build setting.

By : lajos


Returning an exact number of results is not worth the overhead to accurately calculate. Since there's not much of a value add from knowing there was 1,004,345 results rather than 'about 1,000,000', it's more important from an end user experience perspective to return the results faster rather than the additional time to calculate the total.

From Google themselves: "Google's calculation of the total number of search results is an estimate. We understand that a ballpark figure is valuable, and by providing an estimate rather than an exact account, we can return quality search results faster."

By : mbrevoort


This video can help you solving your question :)
By: admin