如何在Xcode 4中创建项目模板 [英] How to create project templates in Xcode 4

查看:124
本文介绍了如何在Xcode 4中创建项目模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很难找到这样做的教程,因为大多数信息与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/creating-custom-xcode-4-project-templates/
  • http://www.bobmccune.com/2012/03/04/creating-custom-xcode-4-file-templates/

推荐答案

我花了几个小时在网上搜索,找到有关这样做的信息。实际上,为Xcode4.5设置项目模板实际上并不困难,但很难在Web上找到将它们放在一起的信息!希望以下步骤可以帮助您创建自己的。

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.

设置


  1. 让我们首先获取现有Xcode项目模板的副本以用作基础。打开Finder,转到Applications并右键单击Xco​​de以显示包内容。导航到Contents / Developer / Platforms / iPhoneOS.platform / Developer / Library / Xcode / Templates / Project Templates / Application /

]
在Xcode 5中,PATH如下:〜/ Library / Developer / Xcode / Templates / Application / Project Templates。如果模板/应用程序/项目模板不存在,您也应该创建它。感谢seufagner在下面的评论中更新,尽管我自己没有尝试过。
[/ EDIT]

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]


  1. 复制(不要剪切/粘贴! )其中一个列出的模板。

  2. 打开另一个查找器窗口并导航到以下目录(取消隐藏您的Library文件夹,在终端中键入此cmd:chflags nohidden~ / Library /或选择按单击Finder / Go时的alt / option键/ Library / Developer / Xcode / Templates(如果不存在则可能需要创建此文件夹)/ Project Templates /

  3. 创建一个文件夹在这里。无论你想要什么,都可以打电话,建议是你的公司名称。此名称显示在Xcode中新项目对话框的左侧菜单中。例如在附图中我称之为我的Appscore,还有另一个用于cocoas2d。

  4. 粘贴项目模板在这里并将其文件夹名称更改为您想要的任何内容MySuperProjectTemplate.xctemplate。我们还没有完成,因为我们需要更改模板的标识符。否则它将不会出现在Xcode新项目对话窗口中。

  5. 在TextEdit中打开TemplateInfo.plist文件。搜索标识符键。您应该看到类似于com.apple.dt.unit.XXXXXX的字符串值。只要它的独特之处,用你想要的任何东西替换它。我再次建议添加您的公司名称和描述模板的名称。

  6. 如果您现在打开Xcode,您应该会看到项目模板出现在新项目对话框中的公司名称下。

  1. Copy (do not cut/paste!) one of the listed templates.
  2. 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/
  3. 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.
  4. 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.
  5. 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.
  6. 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?


  1. 复制你想要的文件,并将它们粘贴到你的新项目模板中,即导航到/ Library / Developer / Xcode / Templates / Project Templates // MySuperProjectTemplate.xctemplate /

  2. 再次在TextEdit中打开TemplateInfo.plist文件。我们要做的第一件事就是告诉项目模板包含新文件,以便搜索一个名为Nodes的键,它有一个值数组。添加以下两行:

  1. 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/
  2. 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 _ .h< / string>
< 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.h< / string> < string> ___ VARIABLE_classPrefix:identifier ___ BaseViewController.m< / string>

<string>___VARIABLE_classPrefix:identifier___BaseViewController.h</string> <string>___VARIABLE_classPrefix:identifier___BaseViewController.m</string>


  1. 接下来找到Definitions键,你应该看到字典作为其价值。在这里,我们必须添加对包含文件的引用。创建一个新密钥并将其命名为___ VARIABLE_classPrefix:identifier ___ BaseViewController.h(再次以BaseViewController为例)。


  1. 此键的值也是字典。它包含一个名为Path的键和一个字符串值,它是文件的名称,例如BaseViewController.h

  2. 我附上了以下图片,以显示我的意思,因为我认为我的描述不足。您可能会注意到有一个名为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中创建项目模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆