在 Xcode 中添加新模板

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

Add new templates in Xcode

iphonexcodetemplatesadd

提问by

How to add new templates in Xcode for iPhone application developement?

如何在 Xcode 中为 iPhone 应用程序开发添加新模板?

回答by mouviciel

For some advices, I suggest to take a look at answers to a related question: Change templates in Xcode.

对于一些建议,我建议查看相关问题的答案:在 Xcode 中更改模板

In particular, if you want your modifications not to be lost whenever you upgrade Xcode, put your templates in ~/Library/Developer/Shared/Xcode, not under /Developer.

特别是,如果你想让你的修改不会丢失,只要你升级的Xcode,把你的模板~/Library/Developer/Shared/Xcode,而不是下/Developer

回答by Barry Wark

From my answer to thisquestion:

从我对这个问题的回答来看:

XCode uses template files for file and project templates and does variable expansion in both at creation time.

XCode 将模板文件用于文件和项目模板,并在创建时进行变量扩展。

XCode 3.0-3.1 templates can be found in [Dev Installation]/Library/Xcode/, likely /Developer/Library/XCode. If you want to modify these templates or add your own, use the following directories to save your new/modified templates so that they are not wiped out by future Developer Tool upgrades:

XCode 3.0-3.1 模板可以在 [Dev Installation]/Library/Xcode/ 中找到,可能是 /Developer/Library/XCode。如果您想修改这些模板或添加您自己的模板,请使用以下目录来保存您新的/修改过的模板,以便它们不会被未来的开发者工具升级所消灭:

  • File templates: ~/Library/Developer/Shared/Xcode/File Templates/
  • Target templates: ~/Library/Developer/Shared/Xcode/Target Templates/
  • Project templates: ~/Library/Developer/Shared/Xcode/Project Templates/
  • 文件模板:~/Library/Developer/Shared/Xcode/File Templates/
  • 目标模板:~/Library/Developer/Shared/Xcode/Target Templates/
  • 项目模板:~/Library/Developer/Shared/Xcode/Project Templates/

I think that you can also use the /Library/Developer/Shared/Xcode/[File|Target|Project] Templates/ directory for templates shared by all users.

我认为您还可以将 /Library/Developer/Shared/Xcode/[File|Target|Project] Templates/ 目录用于所有用户共享的模板。

A good tutorial on writing file templates is here[MacResearch.org].

关于编写文件模板的一个很好的教程在这里[MacResearch.org]。

回答by miniiphoneprogrammer

You can make a template through changing the contents of the developer folder. I have done this myself. Let's say, you were making an html template: Step 1. Go to:/Developer/Library/Xcode/Templates/file templates/resource Step 2. make a folder there called HTML File.xctemplate. Step 3. Copy the contents of the RTF file folder Step 4. Paste the contents in your html folder. Step 5. Change the rtf extention of the

您可以通过更改 developer 文件夹的内容来制作模板。我自己已经这样做了。假设您正在制作一个 html 模板: 步骤 1. 转到:/Developer/Library/Xcode/Templates/file templates/resource 步骤 2. 在那里创建一个名为 HTML File.xctemplate 的文件夹。步骤 3. 复制 RTF 文件夹的内容 步骤 4. 将内容粘贴到 html 文件夹中。步骤 5. 更改 rtf 扩展名

___FILEBASENAME___.rtf(in your html folder) to .html

Step 6. Change the plist file to:

步骤 6. 将 plist 文件更改为:

Key                       |         Type   |     Value
DefaultCompletionName            String          File
Description                      String         An empty Hyper Text Markup language (HTML) file.
Kind                             String         Xcode.IDEKit.TextSubstitutionFileTemplateKind
MainTemplateFile                 String         ___FILEBASENAME___.html
Name                             String         Hyper Text Markup Language file
Summary                          String         An empty Hyper Text Markup Language (HTML) file

Step 7. now, when you add a new file, if you go to resources, you will find an html template. PS You just need to replace the html text to your choice, such as ruby.

Step 7. 现在,当你添加一个新文件时,如果你去资源,你会发现一个 html 模板。PS 您只需要将 html 文本替换为您选择的,例如 ruby​​。

回答by Kendall Helmstetter Gelner

XCode 4 changes how templates work, and where templates go, so be careful following instructions unless they refer to XCode 4. You can find a few template examples, and the paths to where they go in my XCode4 customization repository:

XCode 4 更改了模板的工作方式以及模板的位置,因此请小心遵循说明,除非它们参考 XCode 4。您可以在我的 XCode4 自定义存储库中找到一些模板示例,以及它们所在位置的路径:

https://github.com/KiGi/XCode4Customization

https://github.com/KiGi/XCode4Customization

The paths where the system templates live is:

系统模板所在的路径是:

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

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/文件模板

Don't change those, copy and modify in your own library directory:

不要更改这些,在您自己的库目录中复制和修改:

~/Library/Developer/Xcode/UserData/File Templates

~/Library/Developer/Xcode/UserData/文件模板

Those paths are also in the "WhereToPlaceFiles" RTF file on github.

这些路径也在 github 上的“WhereToPlaceFiles”RTF 文件中。

回答by jithp2

You can use this template which is a well researched one available in the market.

您可以使用此模板,该模板是市场上经过充分研究的模板。

http://www.binpress.com/app/ios-boilerplate-and-template/1597

http://www.binpress.com/app/ios-boilerplate-and-template/1597

回答by P i

I wrote an article on how to create a new Xcode template from an existing project here.

我写了一篇关于如何从现有项目中创建一个新的Xcode模板的文章在这里

It covers:

它涵盖:

  • specifying your project files are relative to the project path
  • using the commandline to search / replace & fiddle file permissions
  • excluding info.plist from the target membership
  • giving your template an icon
  • 指定您的项目文件是相对于项目路径
  • 使用命令行搜索/替换和修改文件权限
  • 从目标成员资格中排除 info.plist
  • 给你的模板一个图标

It doesn't cover where to put the template. That information is covered in other answers.

它不包括放置模板的位置。该信息包含在其他答案中。