Xcode 利用宏定义区分iphone 模拟器和真机

这篇博客介绍了如何利用Xcode中的宏定义`TARGET_IPHONE_SIMULATOR`和`TARGET_OS_IPHONE`来区分代码是在iPhone模拟器还是真机上运行。代码示例展示了根据不同条件为UILabel设置不同的文本。
摘要由CSDN通过智能技术生成


 

#if TARGET_IPHONE_SIMULATOR

  label . text = @"iphoneSimulator" ;

#elif TARGET_OS_IPHONE

label . text = @"iphoneDevice" ;

#endif

 

/*

     File:       TargetConditionals.h

 

     Contains:   Autoconfiguration of TARGET_ conditionals for Mac OS X and iPhone

    

                 Note:  TargetConditionals.h in 3.4 Universal Interfaces works

                        with all compilers.  This header only recognizes compilers

                        known to run on Mac OS X.

 

     Copyright:  (c) 2000-2008 by Apple Inc., all rights reserved.

 

*/

 

#ifndef __TARGETCONDITIONALS__

#define __TARGETCONDITIONALS__

/****************************************************************************************************

 

    TARGET_CPU_*   

    These conditionals specify which microprocessor instruction set is being

    generated.  At most one of these is true, the rest are false.

 

        TARGET_CPU_PPC          - Compiler is generating PowerPC instructions for 32-bit mode

        TARGET_CPU_PPC64        - Compiler is generating PowerPC instructions for 64-bit mode

        TARGET_CPU_68K          - Compiler is generating 680x0 instructions

        TARGET_CPU_X86          - Compiler is generating x86 instructions

        TARGET_CPU_ARM           - Compiler is generating ARM instructions

        TARGET_CPU_MIPS         - Compiler is generating MIPS instructions

        TARGET_CPU_SPARC        - Compiler is generating Sparc instructions

        TARGET_CPU_ALPHA        - Compiler is generating Dec Alpha instructions

 

 

    TARGET_OS_*

    These conditionals specify in which Operating System the generated code will

    run. At most one of the these is true, the rest are false.

 

        TARGET_OS_MAC           - Generate code will run under Mac OS

        TARGET_OS_WIN32         - Generate code will run under 32-bit Windows

        TARGET_OS_UNIX          - Generate code will run under some non Mac OS X unix

        TARGET_OS_EMBEDDED      - Generate code will run under an embedded OS variant

                                   of one of the above OSes. Can be true at the same

                                  time as TARGET_OS_MAC

        TARGET_OS_IPHONE        - Generate code will run under iPhone OS

 

    TARGET_RT_*

    These conditionals specify in which runtime the generated code will

    run. This is needed when the OS and CPU support more than one runtime

    (e.g. Mac OS X supports CFM and mach-o).

 

        TARGET_RT_LITTLE_ENDIAN - Generated code uses little endian format for integers

         TARGET_RT_BIG_ENDIAN    - Generated code uses big endian format for integers   

        TARGET_RT_64_BIT        - Generated code uses 64-bit pointers   

        TARGET_RT_MAC_CFM       - TARGET_OS_MAC is true and CFM68K or PowerPC CFM (TVectors) are used

        TARGET_RT_MAC_MACHO     - TARGET_OS_MAC is true and Mach-O/dlyd runtime is used

 

 

    TARGET_IPHONE_SIMULATOR     - Generate code for running under iPhone Simulator

       

 

****************************************************************************************************/

 

 

/*

  *    gcc based compiler used on Mac OS X

  */

#if defined(__GNUC__) && ( defined(__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__MACOS_CLASSIC__) )

    #define TARGET_OS_MAC               1

    #define TARGET_OS_WIN32             0

    #define TARGET_OS_UNIX              0

    #define TARGET_OS_EMBEDDED          1

    #define TARGET_OS_IPHONE            1

    #define TARGET_IPHONE_SIMULATOR     0

    #if defined(__ppc__)

        #define TARGET_CPU_PPC          1

        #define TARGET_CPU_PPC64        0

        #define TARGET_CPU_68K          0

        #define TARGET_CPU_X86          0

        #define TARGET_CPU_X86_64       0

        #define TARGET_CPU_ARM          0

        #define TARGET_CPU_MIPS         0

       

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值