如何为Xcode 6创build自定义的Swift文件模板?

我想制作几个Swift文件模板,我可以放入Xcode的文件模板select器中。 我知道如何制作一个自定义的Playground模板和Obj-C文件模板,但是对于Swift来说,在下面的path中似乎没有可用的文件模板:

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

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

我在path下创build了一个新的模板文件夹

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

与名称Swift File.xctemplate和以下内容:

 ___FILEBASENAME___.swift TemplateIcon.png TemplateIcon@2x.png TemplateInfo.plist 

当然编辑相应的文件。 当我打开Xcode的寺庙select器,我的模板出现,但它以某种方式无法正常工作。 它还会打开一个文件浏览器,并询问哪里存储的文件不正确,文件之后不会出现在项目中。

有没有解决这个问题? networking似乎没有这样的信息。

使用Xcode版本6.1.1(6A2008a),如果你进入到/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source你会看到快速的模板。

所以,举个例子,让我们打开一个新的terminal窗口,看看Cocoa Touch Class.xctemplate包内部,看看所有的swift模板:

 $ 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 ... 

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

有几件事情总能帮助我:

1)检查,复查和三重检查你的TemplateInfo.plist文件,这是TemplateInfo.plist中最重要的文件,最容易搞砸了。

2)有时,当我不能让Xcode识别我的新模板,或者改变现有的模板,然后重新启动dang的东西,有时会产生奇迹。