如何在XCode上查看我的iPhone应用程序的TARGET_NAME? [英] How do I check the TARGET_NAME of my iPhone app on XCode?

查看:222
本文介绍了如何在XCode上查看我的iPhone应用程序的TARGET_NAME?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在同一个XCode项目中拥有2个版本的iPhone应用程序。
代码库几乎相同,我需要有不同的行为,我决定使用预处理器的条件和 $ {TARGET_NAME} 标记。

I'm trying to have 2 version of my iPhone application within the same XCode project. The codebase it's almost the same and where I need to have different behaviours I've decided to use preprocessor's conditionals and the ${TARGET_NAME} tag.

我已将 OTHER_CFLAGS 设置为包含 -DTARGET_NAME = $ {TARGET_NAME}

然后在我的代码中我尝试了

Then in my code I tried to do

#if TARGET_NAME == myApp
  NSLog(@"pro");
#elif TARGET_NAME == myAppLite
  NSLog(@"lite");
#endif

不幸的是,自 TARGET_NAME == myApp 它始终为真:因为定义了 TARGET_NAME 。我不能为我的生活弄清楚如何评估这个字符串比较。
有什么想法吗?

Unfortunately I always get "lite" printed out since TARGET_NAME == myApp it's always true: since TARGET_NAME is defined. I cannot for the life of me figure out how to evaluate this string comparison. Any idea?

提前谢谢

推荐答案

您无法比较 #if 块中的字符串。而是将定义添加到每个特定目标。例如,在完整版的目标上,打开信息面板并转到构建选项卡,并将 FULL_VERSION 之类的内容添加到 GCC_PREPROCESSOR_DEFINITIONS 构建设置。然后,对于lite目标,输入类似 LITE_VERSION 的内容。在你的代码中,你可以这样做:

You can't compare strings like that in an #if block. Instead, add the defines to each specific target. For instance, on the full version's target, open the Info panel and go to the build tab and add something like FULL_VERSION to the GCC_PREPROCESSOR_DEFINITIONS build setting. Then, for the lite target, enter something like LITE_VERSION. In your code, you can do:

#ifdef FULL_VERSION
NSLog(@"Full");
#else
NSLog(@"Lite");
#endif

这篇关于如何在XCode上查看我的iPhone应用程序的TARGET_NAME?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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