Compiling Source Code Conditionally for iOS App 模拟器条件编译,判断是IOS还是MAC

来源:互联网 发布:java编译器eclipse 编辑:程序博客网 时间:2024/04/29 20:31

Listing 2-1  Determining whether you’re compiling for a simulator

// Set hello to "Hello, <device or simulator>"!


#if TARGET_IPHONE_SIMULATOR


   NSString *hello = @"Hello, iOS Simulator!";


#else


   NSString *hello = @"Hello, iOS device!";


#endif


Listing 2-2 shows how to use the TARGET_OS_IPHONE macro in a source file to be shared between Mac OS X and iOS.

Listing 2-2  Determining whether you’re compiling for a device

#if TARGET_OS_IPHONE


   #import <UIKit/UIKit.h>


#else


   #import <Cocoa/Cocoa.h>


#endif


The TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR macros are defined in the TargetConditionals.h header file.

原创粉丝点击