完全更改 Xcode 中所有新文件的整个“标题”

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

Totally change entire "header" on ALL new files in Xcode

xcodetemplatesxcode5

提问by Fattie

When you create any file in Xcode you get:**

当您在 Xcode 中创建任何文件时,您会得到:**

enter image description here

在此处输入图片说明

Is there a way to completely CHANGE that template?

有没有办法完全改变那个模板?

(It's trivial to change the corporate name, etc. How to change the actual template?)

(更改公司名称等微不足道,实际模板如何更改?)

I do not care, at all, if I have to redo the change each time Xcode is upgraded.

我根本不在乎每次 Xcode 升级时是否必须重做更改。



FYI Years later, correct solution - https://stackoverflow.com/a/57510348/294884

仅供参考多年后,正确的解决方案 - https://stackoverflow.com/a/57510348/294884

回答by Mark Szymczyk

The file template creation process did not change in Xcode 5 so any information you found for Xcode 4 should also work in Xcode 5. But to answer your question, you have to create a custom file template. Duplicate one of Apple's file templates, which are in Xcode's application bundle. The iOS file templates are in the following location in Xcode 5:

Xcode 5 中的文件模板创建过程没有改变,因此您为 Xcode 4 找到的任何信息也应该在 Xcode 5 中有效。但是要回答您的问题,您必须创建一个自定义文件模板。复制 Apple 的文件模板之一,这些模板位于 Xcode 的应用程序包中。iOS 文件模板位于 Xcode 5 中的以下位置:

Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates

The rest of Apple's file templates are in the following location in Xcode 5:

Apple 的其余文件模板位于 Xcode 5 中的以下位置:

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

Selecting the Xcode application from the Finder, right-clicking, and choosing Show Package Contents will take you to the Contents directory inside the application bundle.

从 Finder 中选择 Xcode 应用程序,右键单击并选择 Show Package Contents 将带您到应用程序包内的 Contents 目录。

Place your copy of the file template in the following location:

将文件模板的副本放在以下位置:

/Users/YourUsername/Library/Developer/Xcode/Templates/File Templates/GroupName

GroupName is the name of the category on the left side of the New File Assistant. You can create your own group name or use one of the built-in names. Your file template will appear in the GroupName category.

GroupName 是新建文件助手左侧的类别名称。您可以创建自己的组名或使用内置名称之一。您的文件模板将出现在 GroupName 类别中。

Now it's time to edit your copy of Apple's file template. Inside the .xctemplate folder you should see the following files for Objective-C file templates:

现在是编辑 Apple 文件模板副本的时候了。在 .xctemplate 文件夹中,您应该会看到以下用于 Objective-C 文件模板的文件:

___FILEBASENAME___.h
___FILEBASENAME___.m

There are triple underscores before and after FILEBASENAME. Open the FILEBASENAME files in Xcode and modify them to suit your needs. In your case that would involve changing the comments at the top of the file.

FILEBASENAME 前后有三个下划线。在 Xcode 中打开 FILEBASENAME 文件并修改它们以满足您的需要。在您的情况下,这将涉及更改文件顶部的注释。

Whether or not creating custom file templates is practical depends on how many of Apple's file templates you want to duplicate. Duplicating every one of Apple's file templates would be impractical, but duplicating Apple's Cocoa Touch file templates would be more practical.

创建自定义文件模板是否实用取决于您要复制多少 Apple 的文件模板。复制 Apple 的每一个文件模板是不切实际的,但复制 Apple 的 Cocoa Touch 文件模板会更实用。

回答by guptron

There's a post here with a detailed guide. To access the original templates, you'll need to open the Xcode app bundle as mentioned in Mark's answer.

这里有一个帖子,里面有详细的指南。要访问原始模板,您需要打开 Mark 的回答中提到的 Xcode 应用程序包。

http://meandmark.com/blog/2011/11/creating-custom-xcode-4-file-templates/

http://meandmark.com/blog/2011/11/creating-custom-xcode-4-file-templates/