本文介绍了如何为Xcode 6创建自定义Swift文件模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一些Swift文件模板,我可以将其放入Xcode的文件模板选择器中。我知道如何制作自定义Playground模板和Obj-C文件模板但是对于Swift,似乎在以下路径中根本没有可用的文件模板:

I'd like to make a couple of Swift file templates that I can drop into Xcode's file template picker. I know how to make a custom Playground template and Obj-C file templates but for Swift there seems to be no file template available at all in the following path:

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

这肯定是可能的,不应该吗? (或者每个应用程序开发人员都会使用糟糕的默认模板吗?)

This surely should be possible, shouldn't it? (Or does every app developer start with the awful default templates?)

我在路径下创建了一个新的模板文件夹

I've created a new template folder under the path

/Users/name/Library/Developer/Xcode/Templates/File Templates/User Templates

名称 Swift File.xctemplate 以及以下内容:

___FILEBASENAME___.swift
TemplateIcon.png
[email protected]
TemplateInfo.plist

当然也会相应地编辑文件。当我打开Xcode的寺庙选择器时,我的模板出现但它不知何故无法正常工作。它还会打开一个文件浏览器,询问存放不正确的文件的位置,然后该文件不会出现在项目中。

and of course edited the files accordingly. When I open Xcode's temple chooser, my template appears but it somehow doesn't work correctly. It also opens a file browser and asks where to store the file which isn't right, and the file doesn't appear in the project afterwards.

有什么解决方案吗?这个?网络似乎没有这些信息。

Is there any solution to this? The web seems to be devoid of such information.

推荐答案

使用Xcode版本6.1.1(6A2008a),如果你进入一个在 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates / Source you'中找到的模板包我会看到swift模板。

Using Xcode Version 6.1.1 (6A2008a), if you go into one of the template bundles found in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source you'll see the swift templates.

所以,例如,让我们打开一个新的终端窗口并查看 Cocoa Touch Class.xctemplate 包查看所有swift模板:

So, for example, let's open up a new Terminal window and look inside the Cocoa Touch Class.xctemplate bundle to see all the swift templates:

$ cd "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/Cocoa Touch Class.xctemplate"
$ ls *Swift
NSObjectSwift:
___FILEBASENAME___.swift
...

这应该给你一个开始寻找的好地方,这样你就可以弄清楚你的自定义模板出了什么问题。

That should give you a good place to start looking so you can figure out what has gone wrong with your custom template.

总有助于我的一些事情是:

A couple things that always help me are:

1)检查,仔细检查和三重检查你的 TemplateInfo.plist 文件,它是模板中最重要的文件,也是最容易搞砸的。

1) Check, double check, and triple check your TemplateInfo.plist file, it's the most important file in the template and the easiest to mess up.

2)有时,当我无法让Xcode识别我的新模板或更改现有模板时,重新启动dang的东西有时会产生奇迹。

2) Sometimes, when I can't get Xcode to recognize my new template, or changes to an existing template, then restarting the dang thing sometimes works wonders.

这篇关于如何为Xcode 6创建自定义Swift文件模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:06