views:

131

answers:

1

Two questions:

this code

#ifdef __IPHONE_3_0
    // iPhone 3.0 specific stuff
#else
    // iPhone 2.2 specific stuff
#endif

compiles specific codes for specific versions of the iPhone. How could this be transformed to compile for a range of devices? For example: if iphone version < 3.1 or if version >= 3.2, and so one...

2) where do I get a list of all conditionals allowed by Xcode?

thanks for any help.

+1  A: 

Those defines are found in Availability.h, located within whatever SDK you are using. For example, you can find a version for the 3.0 simulator at

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/Availability.h

As a note, it's easy to look up constants like __IPHONE_3_0 by highlighting them, right-clicking, and selecting "Jump To Definition" from the pop-up menu.

In Availability.h, the header itself describes in detail how to selectively compile for various versions. For example, to compile code only if the iPhone OS version is greater than 3.0, you could use

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0
// Your code here
#endif

Note that this is for determining what to include at compile time, not for selectively enabling code based on what version of the OS the application is running on.

Brad Larson
THANKS! You are the man!
Digital Robot