Which conditional compile to use to switch between Mac and iPhone specific code?

后端 未结 4 1803
甜味超标
甜味超标 2020-12-02 11:07

I am working on a project that includes a Mac application and an iPad application that share code. How can I use conditional compile switches to exclude Mac-specific code f

4条回答
  •  清歌不尽
    2020-12-02 11:45

    You've made a mistake in your observations. :)

    TARGET_OS_MAC will be 1 when building a Mac or iPhone application. You're right, it's quite useless for this sort of thing.

    However, TARGET_OS_IPHONE is 0 when building a Mac application. I use TARGET_OS_IPHONE in my headers all the time for this purpose.

    Like this:

    #if TARGET_OS_IPHONE
    // iOS code
    #else
    // OSX code
    #endif
    

    Here's a great chart on this: http://sealiesoftware.com/blog/archive/2010/8/16/TargetConditionalsh.html

提交回复
热议问题