问题描述
由于大多数信息都与 Xcode 3 相关,因此很难找到执行此操作的教程.下面的答案可能对某些人有所帮助.
Its really hard to find a tutorial to do this as most information relates to Xcode 3. Answer below may help some people.
我的大部分信息来自以下网站:
I sourced most of my information for the answer below from the following sites:
- http://meandmark.com/blog/2011/12/创建自定义xcode-4-project-templates/
- http://www.bobmccune.com/2012/03/04/creating-custom-xcode-4-file-templates/
推荐答案
我花了几个小时在网上搜索有关执行此操作的信息.为 Xcode4.5 设置项目模板实际上并不难,但很难在网络上找到将它们组合在一起的信息!希望以下步骤能帮助您创建自己的.
I spent hours searching the web to find information about doing this. Its not actually that hard to set up project templates for Xcode4.5 but its hard to find information on the web that puts it all together! Hopefully the steps below will help you to create your own.
设置
- 让我们首先获取现有 Xcode 项目模板的副本以用作基础.打开 finder,转到 Applications 并右键单击 Xcode 以显示包内容.导航到 Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/
在 Xcode 5 中,PATH 如下所示:~/Library/Developer/Xcode/Templates/Application/Project Templates.如果模板/应用程序/项目模板不存在,您也应该创建它.尽管我自己没有尝试过,但请在下面的评论中感谢 seufagner 的更新.[/编辑]
In Xcode 5 the PATH is as follows: ~/Library/Developer/Xcode/Templates/Application/Project Templates. If Templates/Application/Project Templates not exists you should create it too. Credit to seufagner in the comments below for the update although I have not tried this myself.[/EDIT]
- 复制(不要剪切/粘贴!)列出的模板之一.
- 打开另一个 finder 窗口并导航到以下目录(要取消隐藏您的 Library 文件夹,请在终端中键入此 cmd:chflags nohidden ~/Library/或在单击 Finder/Go 时选择按 alt/option 键)/Library/Developer/Xcode/Templates(如果此文件夹尚未存在,您可能需要创建)/Project Templates/
- 在此处创建一个文件夹.随意称呼它,建议是您的公司名称.此名称出现在 Xcode 中新项目对话框的左侧菜单中.例如在我称为我的 Appscore 的附加图像中,还有另一个用于 cocoas2d.
- 将项目模板粘贴到此处并将其文件夹名称更改为您想要的任何名称,例如MySuperProjectTemplate.xctemplate.我们还没有完成,因为我们需要更改模板的标识符.否则它不会出现在 Xcode 新建项目对话窗口中.
- 在 TextEdit 中打开 TemplateInfo.plist 文件.搜索标识符键.您应该会看到类似于com.apple.dt.unit.XXXXXX"的字符串值.只要它是独一无二的,就用你想要的任何东西替换它.我再次建议添加您的公司名称和描述模板的名称.
- 如果您现在打开 Xcode,您应该会在新项目对话框中看到出现在您公司名称下的项目模板.
- Copy (do not cut/paste!) one of the listed templates.
- Open another finder window and navigate to the following directory (to unhide your Library folder type this cmd in terminal: chflags nohidden ~/Library/ or select press the alt/option key when clicking on Finder/Go) /Library/Developer/Xcode/Templates (you may need to create this folder if not already present) /Project Templates/
- Create a folder in here. Call it whatever you wish, a suggestion is your company name. This name appears in the left hand menu of the new project dialogue in Xcode. e.g. in the attached image I've called mine Appscore, there's another one there for cocoas2d.
- Paste the project template in here and change its folder name to whatever you wish e.g. MySuperProjectTemplate.xctemplate. We are not done yet though as we need to change the template's identifier. Otherwise it will not appear in the Xcode new project dialogue window.
- Open the TemplateInfo.plist file in TextEdit. Search for the Identifier key. You should see a string value something similar to "com.apple.dt.unit.XXXXXX". Replace this with whatever you wish as long as its unique. I again suggest adding your company name and a name that describes the template.
- If you now open Xcode you should see the project template appearing under your company name in the new project dialogue.
定制
目前您有一份现有项目模板的副本,但不是很有用.我猜你有很多类可以在你几乎所有的项目中重用?我们将它们包含在这个模板中怎么样?
At the moment you have a copy of an existing project template which is not very useful. I'm guessing you have a number of classes that get reused in nearly all your projects? How about we include them into this template?
- 复制您想要的文件,并将它们粘贴到您的新项目模板中,即导航至/Library/Developer/Xcode/Templates/Project Templates//MySuperProjectTemplate.xctemplate/
再次在 TextEdit 中打开 TemplateInfo.plist 文件.我们要做的第一件事是告诉项目模板包含新文件,因此搜索具有值数组的名为Nodes"的键.添加以下两行:
- Copy the files you wish, and paste them into your new project template i.e. navigate to /Library/Developer/Xcode/Templates/Project Templates//MySuperProjectTemplate.xctemplate/
Open the TemplateInfo.plist file in TextEdit again. First thing we have to do is tell the project template to include the new files so search for a key called "Nodes" that has an array of values. Add the two following lines:
<string>_VARIABLE_classPrefix:identifier_.m</string>
<string>_VARIABLE_classPrefix:identifier_.h</string><string>_VARIABLE_classPrefix:identifier_.m</string>
例如,如果您的控制器名为 BaseViewController,则行将如下所示:
For example if your controller was called BaseViewController the lines would look like:
<string>___VARIABLE_classPrefix:identifier___BaseViewController.m</string>
- 接下来找到 Definitions 键,您应该会看到一个字典作为其值.在这里,我们必须添加对包含文件的引用.创建一个新的键并将其命名为 ___VARIABLE_classPrefix:identifier___BaseViewController.h(再次以 BaseViewController 为例).
- 这个键的值又是一个字典.它包含一个名为 Path 的键和一个字符串值,它是文件的名称,例如BaseViewController.h
- 我附上了以下图片来说明我的意思,因为我认为我的描述不够完整.您可能会注意到其中有一个名为Group"的键,您可以猜到它允许您直接创建组和输入文件:D
希望这对某人真的有用:) 任何问题都在下面评论,我会尽力回答.我是几周前做的,所以我的记忆有点模糊.
Hope this is actually useful to someone :) Any questions comment below and I'l do my best to answer. I did this a few weeks ago so my memory is a little hazy.
这篇关于如何在 Xcode 4 中创建项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!