␡
- Creating New Projects
- Building Hello World the Template Way
- Using the Simulator
- The Minimalist Hello World
- Converting Interface Builder Files to Their Objective-C Equivalents
- Using the Debugger
- Memory Management
- Recipe: Using Instruments to Detect Leaks
- Recipe: Using Instruments to Monitor Cached Object Allocations
- Analyzing Your Code
- Building for the iOS Device
- Detecting Simulator Builds with Compile-Time Checks
- Performing Runtime Compatibility Checks
- Pragma Marks
- Preparing for Distribution
- Over-the-Air Ad Hoc Distribution
- Submitting to the App Store
- Summary
This chapter is from the book
Detecting Simulator Builds with Compile-Time Checks
Xcode directives issue instructions to the compiler that can detect the platform you’re building for. This lets you customize your application to safely take advantage of device-only features when they’re available. Adding #if statements to your code lets you block or reveal functionality based on these options. To detect if your code is compiled for the simulator or for an iOS device, use a compile-time check:
#if TARGET_IPHONE_SIMULATOR Code specific to simulator #else Code specific to iPhone #endif