检查正在执行的目标

时间:2011-11-07 21:26:45

标签: objective-c xcode target

所以我有两个目标:1是我的应用程序,另一个是单元测试。

在我的代码中,我需要知道它运行的目标,以便在运行单元测试时跳过块代码。这可能吗?

#ifdef "Some how figure out what target we are in"
// run this code if we are not running the unit test target
#endif

1 个答案:

答案 0 :(得分:0)

在单元测试目标构建设置中,您可以添加预处理器宏(例如,调用TARGET_IS_UNIT_TESTING)。然后如你所说

#ifndef TARGET_IS_UNIT_TESTING
// run this code if we are not running the unit test target
#endif

#ifdef TARGET_IS_UNIT_TESTING
// run this code if we are running the unit test target
#endif