在为iPhone编译时,Xcode设置了哪些#defines [英] What #defines are set up by Xcode when compiling for iPhone

查看:208
本文介绍了在为iPhone编译时,Xcode设置了哪些#defines的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些半便携式代码,希望能够检测到我在为iPhone编译时的情况。所以我想要像 #ifdef IPHONE_SDK ...

I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like #ifdef IPHONE_SDK....

据推测,Xcode定义了一些东西,但我在项目属性下看不到任何东西,谷歌也没什么帮助。

Presumably Xcode defines something, but I can't see anything under project properties, and Google isn't much help.

推荐答案

它位于有条件地编译源代码下的SDK文档中

It's in the SDK docs under "Compiling source code conditionally"

相关定义为TARGET_OS_IPHONE(并且他已弃用TARGET_IPHONE_SIMULATOR),在iOS框架中的/usr/include/TargetConditionals.h中定义。在早期版本的工具链中,你必须写:

The relevant definitions are TARGET_OS_IPHONE (and he deprecated TARGET_IPHONE_SIMULATOR), which are defined in /usr/include/TargetConditionals.h within the iOS framework. On earlier versions of the toolchain, you had to write:

#include "TargetConditionals.h"

但当前(xCode 6 / iOS8)工具链不再需要这样做。

but this is no longer necessary on the current (xCode 6/iOS8) toolchain.

因此,例如,如果您只想构建一个代码块,那么您应该这样做

So, for example, if you want to only compile a block of code if you are building for the device, then you should do

#if !(TARGET_OS_SIMULATOR)
...
#endif

这篇关于在为iPhone编译时,Xcode设置了哪些#defines的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆