更改 Xcode 中的默认标题注释许可

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2381149/
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:18:26  来源:igfitidea点击:

Changing the default header comment license in Xcode

xcode

提问by Erik Rothoff

Whenever I create a new .cpp/.h file in Xcode a comment is added to the top of the file. For example:

每当我在 Xcode 中创建一个新的 .cpp/.h 文件时,都会在文件顶部添加一条注释。例如:

/*
 *  <file>.cpp
 *  <Name of project>
 *
 *  Created by <My name> on <Date>.
 *  Copyright <Year and company>. All rights reserved.
 *
 */

I want to change the default comment to be another license, like GPL/LGPL/ or something else. Is there somewhere I can change this behavior in Xcode?

我想将默认注释更改为另一个许可证,例如 GPL/LGPL/ 或其他许可证。有什么地方可以在 Xcode 中改变这种行为吗?

采纳答案by conorgriffin

/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates

any update of your SDK will wipe changes here so keep your template backed up somewhere else

您的 SDK 的任何更新都会清除此处的更改,因此请将您的模板备份到其他地方

回答by abdullahselek

With Xcode 9there is a built-in option which you can find in the details below.

随着Xcode的9有,你可以在下面的详细信息找到一个内置的选项。

  1. Create a property list file named IDETemplateMacros.plist
  2. Add a FILEHEADERvalue to the Root and set its string value with your copyright text like Copyright ? 2017 ...
  3. Copy the file to one of the following locations
    • For a single project and user <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    • For all team members in a single project <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
    • For all projects in a workspace for a single user <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    • For all projects in a workspace for all team members <WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist
    • For everything you work on, regardless of project ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist
  4. Create a new file - you should see the new copyright header
  1. 创建一个名为 IDETemplateMacros.plist 的属性列表文件
  2. FILEHEADER向 Root添加一个值并使用您的版权文本设置其字符串值,例如Copyright ? 2017 ...
  3. 将文件复制到以下位置之一
    • 对于单个项目和用户 <ProjectName>.xcodeproj/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    • 对于单个项目中的所有团队成员 <ProjectName>.xcodeproj/xcshareddata/IDETemplateMacros.plist
    • 对于单个用户的工作区中的所有项目 <WorkspaceName>.xcworkspace/xcuserdata/[username].xcuserdatad/IDETemplateMacros.plist
    • 对于所有团队成员的工作区中的所有项目 <WorkspaceName>.xcworkspace/xcshareddata/IDETemplateMacros.plist
    • 对于您所做的一切,无论项目如何 ~/Library/Developer/Xcode/UserData/IDETemplateMacros.plist
  4. 创建一个新文件 - 您应该会看到新的版权标题

Sample IDETemplateMacros.plistfor copy and paste:

IDETemplateMacros.plist复制和粘贴示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>FILEHEADER</key>
    <string>
//  Created by Your Name on 29.12.17.
//  Copyright ? 2017 Your Company. All rights reserved.
//  </string>
</dict>
</plist>

回答by ChrisJF

First try changing your Name and Organization your contact card in Address Book.

首先尝试在地址簿中更改您的姓名和组织您的联系人卡片。

If that doesn't work, open System Preferences> Users & Groups > Right click on your user (System Preferences must already be unlocked) > Advanced Options... > Change the name in the Full Nametext box.

如果这不起作用,请打开系统偏好设置> 用户和组> 右键单击​​您的用户(系统偏好设置必须已解锁)> 高级选项...> 在全名文本框中更改名称

To change the organization name in Xcode click on the project fileso it is selected (left sidebar of Xcode in the Project navigator) > In the File Inspector (right sidebar of Xcode) change the Organizationtext box.

要在 Xcode 中更改组织名称,请单击项目文件使其被选中(项目导航器中 Xcode 的左侧栏)> 在文件检查器(Xcode 的右侧栏)中更改组织文本框。

Organization text box

组织文本框

回答by Roy Clarkson

This blog post has some good steps for modifying file templates in Xcode 4.3:

这篇博文有一些在 Xcode 4.3 中修改文件模板的好步骤:

http://error-success.piku.org.uk/2012/04/27/how-to-make-xcode-4-3-2-templates/

http://error-success.piku.org.uk/2012/04/27/how-to-make-xcode-4-3-2-templates/

The /Developerfolder no longer exists, so you copy the templates from within the Xcode.app bundle located in /Applications:

/Developer文件夹不再存在,因此您可以从位于以下位置的 Xcode.app 包中复制模板/Applications

/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File\ Templates/

And place your modified copy here, as before:

并将修改后的副本放在这里,就像以前一样:

~/Library/Developer/Xcode/Templates/File\ Templates/

UPDATE:I decided to write a script that would extract the built in Xcode templates and replace the headers. Source and instructions can be found at the following url:

更新:我决定编写一个脚本来提取内置的 Xcode 模板并替换标头。来源和说明可以在以下网址找到:

https://github.com/royclarkson/xcode-templates

https://github.com/royclarkson/xcode-templates

回答by user151019

Don't edit anything in /Developer as Apple can overwrite this at any time.

不要在 /Developer 中编辑任何内容,因为 Apple 可以随时覆盖它。

The following works for Xcode 4, 5 and 6 except later source differs and is under /Applications

以下适用于 Xcode 4、5 和 6,但后面的源代码不同并且位于 /Applications 下

Instead copy the templates that you want to change from /Applications/Xcode<version>.app/Contents/Developer/Library/Xcode/Templatesto ~/Library/Developer/Xcode/Templates/File Templatesand then edit the files keeping the same directory structure but edit the directory name that is the template to not show up a a duplicate in Xcode.

相反,复制的模板,你想从改变/Applications/Xcode<version>.app/Contents/Developer/Library/Xcode/Templates~/Library/Developer/Xcode/Templates/File Templates,然后编辑保持相同的目录结构,但编辑的目录名称是模板不会显示在Xcode AA重复的文件。

e.g for a new category of C/C+ files in Xcode 5 copy /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/C and C++to ~/Library/Developer/Xcode/Templates/File Templates/GPL C and C++

例如,对于 Xcode 5 中新类别的 C/C+ 文件复制/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/C and C++~/Library/Developer/Xcode/Templates/File Templates/GPL C and C++

this process is copied from Red Glasses's blog

此过程复制自Red Glasses 的博客

For Xcode 4 the source path is or for Xcode 4 /Developer/Library/Xcode/Templates/File Templates

对于 Xcode 4,源路径是 或 Xcode 4 /Developer/Library/Xcode/Templates/File Templates

回答by Eric Brotto

It's very simple:

这很简单:

  1. Open up terminal
  2. In one line, write the following:

    defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions -dict ORGANIZATIONNAME "Blah, Inc"
    
  1. 打开终端
  2. 在一行中,写下以下内容:

    defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions -dict ORGANIZATIONNAME "Blah, Inc"
    

You don't have to worry about changing directories beforehand or anything else. It works instantly.

您不必担心事先更改目录或其他任何事情。它立即起作用。

回答by Alex Zavatone

– Press ? 1to display the File Navigator.
– Click on the name of your project at the top of the File Navigator.
– Press ??? ?(that's Command Option Shift Return) to view the Version Editor.
– Make sure that the Comparison View is shown(View > Version Editor > Show Comparison View).

– 按? 1显示文件导航器。
– 单击顶部的项目名称File Navigator
– 按??? ?(即 Command Option Shift Return)查看Version Editor.
– 确保显示比较视图 ( View > Version Editor > Show Comparison View)。

This lets you see the raw text of your project's project.pbxproj file.

这使您可以查看项目的 project.pbxproj 文件的原始文本。

– Press ? fto search the project.pbxproj file, paste in ORGANIZATIONNAMEand press Return.

– 按? f搜索 project.pbxproj 文件,粘贴ORGANIZATIONNAME并按 Return。

This is where the name of the organization that follows the copyright text is defined.

这是定义版权文本后的组织名称的地方。

回答by bandejapaisa

Change the details in your Address Book - add a company name. It will pick it up from there.

更改地址簿中的详细信息 - 添加公司名称。它会从那里捡起来。

回答by cit

Try modifying this file:

尝试修改此文件:

/Developer/Library/Xcode/File\ Templates/C\ and\ C++/Header\ File.pbfiletemplate/header.h

回答by Danyal Aytekin

In Xcode 4.2, they're here:

在 Xcode 4.2 中,它们在这里:

/Developer/Library/Xcode/Templates/File Templates