以编程方式确定iOS项目中的当前目标(运行或测试) [英] Programmatically determine current target (run or test) in iOS project

查看:116
本文介绍了以编程方式确定iOS项目中的当前目标(运行或测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发iOS应用程序时,有没有办法以编程方式确定您是否在测试目标中运行代码与常规运行目标?

Is there any way to programmatically determine if you are running code in the Test target vs the regular Run target while developing iOS applications?

我有检查的黑客如果这个变量是nil或者不是因为它只在我的测试目标中,但这看起来很糟糕。

I have the hack of checking if this variable is nil or not as it is only in my test target but this seems pretty hacky.

[[[NSProcessInfo processInfo] environment] objectForKey:@"XCInjectBundle"]


推荐答案

你应在目标设置中为预处理器宏定义适当的值。

You should define proper value for "Preprocessor Macros" in Target Settings.

在运行时,您可以使用 ifdef 句子。

At the run time you can check it with ifdef sentence.

这篇关于以编程方式确定iOS项目中的当前目标(运行或测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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