在每个项目的 Xcode 中定义 __MyCompanyName__?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2008060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:14:33  来源:igfitidea点击:

Define __MyCompanyName__ in Xcode per project?

xcode

提问by Brian Moeskau

I've seen how to define the __MyCompanyName__macro value that displays in all header comments in XCode by defining it globally via a terminal command:

我已经看到如何__MyCompanyName__通过终端命令全局定义它来定义显示在 XCode 中所有标题注释中的宏值:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "My Company";}'

However, I do work under multiple company names and would like an easy way to switch this depending on what project I'm working on. I realize that I can just write a simple shell script to do this, but then I still have to remember to run it every time I open a project. Am I missing an easy way to define this per project statically somewhere? (This seems like a silly hoop to have to jump through... Apple, hello?)

但是,我确实在多个公司名称下工作,并且想要一种简单的方法来根据我正在从事的项目进行切换。我意识到我可以只编写一个简单的 shell 脚本来做到这一点,但是我仍然必须记住每次打开一个项目时都要运行它。我是否缺少一种在某处静态定义每个项目的简单方法?(这似乎是一个必须跳过的愚蠢箍...... Apple,你好?)

采纳答案by Thomas Zoechling

Since Xcode 3.2 (IIRC) this is a per-project setting.
Just "Get Info" on your project in Xcode. It's right there on the "General" tab.

从 Xcode 3.2 (IIRC) 开始,这是每个项目的设置。
只需在 Xcode 中“获取项目信息”即可。它就在“常规”选项卡上。

UpdateThe above answer is for Xcode 3.2. See Sri Sankaran's & aeldron's answers below for Xcode 4.

更新以上答案适用于 Xcode 3.2。有关 Xcode 4,请参阅下面的 Sri Sankaran 和 aeldron 的答案。

UpdateAlso appropriate for Xcode 4 is the first part of trtwn's answer below. in other words, setting the "company" in the address book is one way to solve the problem in case the company will always be the same for all New files created in Xcode on a particular mac.

更新同样适用于 Xcode 4 的是下面 trtwn 答案的第一部分。换句话说,在地址簿中设置“公司”是解决问题的一种方法,以防公司对于特定 Mac 上在 Xcode 中创建的所有新文件始终相同。

回答by Sri Sankaran

Screenshot of Xcode 4.1.

Xcode 4.1 的屏幕截图。

@neoneye See screenshot of how it's done with Xcode 4.1 (OS X Lion -- if that matters).

@neoneye 查看如何使用 Xcode 4.1(OS X Lion - 如果这很重要)完成的屏幕截图。

回答by aeldron

You can set the value in the project's info settings. In Xcode 4:

您可以在项目的信息设置中设置该值。在 Xcode 4 中:

  1. select the blue project icon
  2. open the Utilities Pane if it's closed (Option+Command+1)
  3. Type in the Organization field in the Project Document section.
  1. 选择蓝色项目图标
  2. 如果实用程序窗格已关闭,请打开它(Option+Command+1)
  3. 在项目文档部分的组织字段中键入。

Voila!

瞧!

enter image description here

在此处输入图片说明

回答by trautwein

As for Xcode 4, the Release Notes state

至于 Xcode 4,发行说明状态

The ORGANIZATIONNAME substitution value in templates is now replaced with the Company Name from the current user's Address Book card if present, rather than _MyCompanyName_. If the PBXCustomTemplateMacroDefinitions user default has already been set, it will be honored.

模板中的 ORGANIZATIONNAME 替换值现在替换为当前用户地址簿卡中的公司名称(如果存在),而不是 _ MyCompanyName_。如果已经设置了 PBXCustomTemplateMacroDefinitions 用户默认值,则它将被遵守。

Yet, the latter was not the case for me.

然而,后者对我来说并非如此。

回答by Brian Moeskau

@weichsel's answer is accepted as it solves this for most normalpeople ;), but I switch this setting often enough that getting the template-generated files with the statically-defined company name is still a bit of an annoyance each time I start a new project. Having to do the "Get Info then type the name" dance also takes up too much time if you do it often enough. Here's my ultimate solution:

@weichsel 的回答被接受,因为它为大多数普通人解决了这个问题;),但是我经常切换这个设置,以至于每次我开始一个新的时,使用静态定义的公司名称获取模板生成的文件仍然有点麻烦项目。如果您经常这样做,则必须进行“获取信息然后输入名称”的舞蹈也会占用太多时间。这是我的最终解决方案:

  • Create a folder like "Set Company" with my shell scripts in it for each company I use
  • Each script contains a version of this terminal command specific to each company:

    defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "My Company";}'

  • I make each script executable so that I can simply double-click in Finder to set my current company. This pagehelped me set this up. Basically, you just

    • Rename each .shscript file to .command
    • Set the permissions of each script to be executable. I couldn't figure out how to do this in Finder, but in terminal it's simply chmod +x mycompany.command
  • 为我使用的每个公司创建一个像“Set Company”这样的文件夹,其中包含我的 shell 脚本
  • 每个脚本都包含特定于每个公司的此终端命令的一个版本:

    defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "My Company";}'

  • 我让每个脚本都可以执行,这样我就可以在 Finder 中简单地双击来设置我当前的公司。 此页面帮助我进行了设置。基本上,你只是

    • 将每个.sh脚本文件重命名为.command
    • 将每个脚本的权限设置为可执行。我不知道如何在 Finder 中执行此操作,但在终端中它只是chmod +x mycompany.command

Easy as that. Now to start a new project I simply double-click whichever company I plan to use then I'm off to coding. Hope this helps someone else.

就这么简单。现在要开始一个新项目,我只需双击我计划使用的任何一家公司,然后我就可以开始编码了。希望这对其他人有帮助。

回答by Best Answer Guy

Best fix for My Company.in XCode 4:

我公司的最佳解决方案在 XCode 4 中:

Open your Address Book card and give yourself a company name. You should do this from System Preferences to make sure you are changing the correct User.

打开您的地址簿卡片并给自己一个公司名称。您应该从系统偏好设置中执行此操作,以确保您更改的是正确的用户。

On you Mac –> Select System Preferences –> Select Users and Groups –> Click once on Your User ID –> Click on Address Book Card ‘Open' button. This is the contact associated with your User account. Add a company name here (just under your name). Close XCode if it's open. Open Xcode and give it a try. Good luck.

在 Mac 上 –> 选择系统偏好设置 –> 选择用户和组 –> 单击您的用户 ID –> 单击通讯簿卡片“打开”按钮。这是与您的用户帐户关联的联系人。在此处添加公司名称(就在您的姓名下方)。如果它是开放关闭的XCode。打开 Xcode 并尝试一下。祝你好运。

回答by Tibidabo

Try this:

尝试这个:

  1. Open Contacts
  2. Make sure you are on the contact list
  3. Make sure your contact card is assigned to "My Card" if not select it from "Make this My Card" from Card menu. enter image description here

  4. Make sure that your companyis set on your card.

  5. Your card should look like this: (on your picture is should say "me") enter image description here
  1. 打开联系人
  2. 确保您在联系人列表中
  3. 如果没有从卡片菜单的“制作这张我的卡片”中选择它,请确保您的联系人卡片已分配给“我的卡片” 。 在此处输入图片说明

  4. 确保您的公司设置在您的卡上。

  5. 你的卡片应该是这样的:(你的照片上应该写着“”) 在此处输入图片说明

Next time you create a new project or create a new file your company name will be as it is defined in your contact card.

下次创建新项目或创建新文件时,您的公司名称将与联系人卡片中定义的名称相同。