如何获取当前在Xcode中运行的目标的名称? [英] How do I get the name of the target that is currently running in Xcode?

查看:94
本文介绍了如何获取当前在Xcode中运行的目标的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个目标的Xcode项目。假设目标名称为 AppFreeVersion AppPaidVersion 。它们共享相同的代码库,但是我想实现一些仅适用于目标之一的逻辑。

I have an Xcode project with several targets. Let's say the target names are AppFreeVersion and AppPaidVersion. They share the same codebase, but I want to implement some logic that is only for one of the targets.

如果不修改我的方案或构建设置,是否有办法得到我当前目标名称的字符串?在此问题中 给出的解决方案要求我在构建设置中传递环境变量,而我不想这样做。

Without modifying my scheme or build settings, is there a way to get the string of my current target name? The solution given in this question requires me to pass an environment variable in the build setting, which I don't want to do.

推荐答案

如何在您的信息中添加 $ {TARGET_NAME} 。 plist?

How about adding ${TARGET_NAME} in your info.plist?

我想你已经知道如何获得它了

And I guess you already know how to get it

Obj-C

[[NSBundle mainBundle] objectForInfoDictionaryKey:key_name];

快速

let targetName = NSBundle.mainBundle().infoDictionary?[key_name] as String

这篇关于如何获取当前在Xcode中运行的目标的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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