Pau*_*aul 3 xcode customization templates
关于自定义模板的主题.我正在教自己如何用xcode 7和Objective c这样做,我被卡住了.到目前为止,通过对SO阅读其他职位我已成功通过复制单一视图的应用之一,并在Xcode包的合适的目录下它来创建自定义模板.我的模板文件夹如下所示:
如果我点击Main.storyboard并说添加几个按钮,并保存,然后在xcode中打开我的自定义模板,按钮就在那里,所以我知道我正在取得进展.我想做的是创建视图控制器文件和xib并包含应用程序图标等...这样我就可以有一个正确的自定义模板来启动我的所有项目.这就是我被困的地方.我不知道如何从简单文件Main.storyboard开始.任何人都可以请我指出正确的方向.
特别是,我正在做的事情是没有一个故事板,并从一个xib开始.我猜我需要用TemplateInfo.plist做点什么.我看了看,看不到任何关于它的东西,所以只需重定向即可.谢谢
cax*_*xix 15
创建Xcode模板可能非常复杂,因为大多数可以编辑项目的东西都可以编写脚本.要重申您已经知道的内容,应该在〜/ Library/Developer/Xcode/Templates目录中创建一个新文件夹.这是Xcode在项目创建时扫描的位置之一.例如,将此文件夹命名为"自定义模板"将使其在Xcode的项目创建对话框中以该名称显示.在此新文件夹中,创建另一个名为"baseApp.xctemplate"的文件夹.一旦我们的所有文件都在其中,这将使名为baseApp的模板出现.
通过复制Xcode的现有模板,可以轻松地启动新模板.主要是因为从头开始编写所有重要的TemplateInfo.plist可能很麻烦.这些文件位于Xcode应用程序中.在Finder中显示其内容并导航至:/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application
从"单一视图应用程序"模板中将所有3个文件复制到之前创建的baseApp.xctemplate文件夹中.下一步是至关重要的,但在此之后,第一个模板已经准备就绪.双击TemplateInfo.plist文件以在Xcode中打开它,并将Identifier键的最后一部分更改为baseApp.就是这样 - Xcode中的新项目对话框现在应该如下图所示.更改TemplateIcon.tiff是个好主意.除此之外,BaseApp还提供了Objective-c以及Swift,Storyboards,CoreData支持等选项.
现在基于新的baseApp模板(无选项)创建一个名为"xibApp"的新Xcode项目.然后按照以下4个步骤:
•删除Main.storyboard和ViewController(移至垃圾箱)
•删除Info.plist中的"主故事板文件基本名称"条目
•添加一个基于UIViewController的名为ViewController的新Cocoa Touch类,并选中该框以包含一个xib文件
•将AppDelegate中的didFinishLaunchingWithOptions函数替换为:
window = UIWindow.init(frame: UIScreen.mainScreen().bounds)
window?.backgroundColor = UIColor.whiteColor()
let viewController = ViewController()
window!.rootViewController = viewController
window!.makeKeyAndVisible()
return true
Run Code Online (Sandbox Code Playgroud)
您现在应该能够运行该应用程序.如果一切正常,请退出Xcode.复制自定义模板目录中的baseApp.xctemplate,并将其重命名为"xibApp.xctemplate".然后删除该目录中的Main.storyboard文件,并将AppDelegate,Info.plist,ViewController.swift和ViewController.xib文件从xibApp文件夹复制到xibApp.xctemplate文件夹.双击xibApp文件夹中的TemplateInfo.plist以在Xcode中打开它,并将标识符重命名为"com.apple.dt.unit.xibApp".另一件需要解决的问题是这个文件中的第一个祖先.它被设置为"com.apple.dt.unit.storyboardApplication",如果留下将使所有结果项目进入故事板项目.为了弥补我们将要创建我们自己的祖先.
Xcode使用祖先层次结构来包含整个项目树.任何扩展名为.xctemplate的文件夹都可以作为祖先,只要它在Xcode目录中 - 无论是app本身还是〜/ Library/Developer/Xcode /.此外,这些目录必须包含正确设置的TemplateInfo.plist文件.因此,抓住位于Xcode应用程序(Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iOS/Application)内容的"Cocoa Touch Application Base.xctemplate"中的TemplateInfo.plist.将此文件放在"自定义模板"文件夹中的新文件夹中,并将文件夹命名为"Custom Xib Base.xctemplate".该文件夹的名称将成为我们祖先的名称.Xcode将删除名称中的所有空格并将其设置为"customXibBase",这是我们新的祖先的扩展名:"com.apple.dt.unit.customXibBase".由于Custom Xib Base.xctemplate文件夹可能成为其他模板的祖先,因此将其移动到自定义模板目录中的新命名的子文件夹(即"共享")可能是个好主意.
返回xibApp.xctemplate目录中的TemplateInfo.plist.双击它,单击Ancestors旁边的显示三角形,然后在第一项下将"storyboardApplication"替换为"customXibBase",以便整行显示"com.apple.dt.unit.customXibBase".最后,我们需要为我们包含的4个文件提供定义和节点,如下图所示(AppDelegate,Info.plist,ViewController.swift和ViewController.xib).保存文件并退出Xcode.全部完成.
如果一切顺利,现在应该在自定义模板类别下面有一个名为xibApp的新项目模板!我认为这对于生成新模板来说是一种可行而且非常糟糕的方法.它可能会破坏Xcode的新版本.但它是进一步探索项目模板的良好开端.
xibApp.xctemplate的最终TemplateInfo.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Kind</key>
<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
<key>Identifier</key>
<string>com.apple.dt.unit.xibApp</string>
<key>Ancestors</key>
<array>
<string>com.apple.dt.unit.customXibBase</string>
<string>com.apple.dt.unit.coreDataCocoaTouchApplication</string>
</array>
<key>Concrete</key>
<true/>
<key>Description</key>
<string>This template provides a starting point for an application that uses a single view. It provides a view controller to manage the view, and a storyboard or nib file that contains the view.</string>
<key>SortOrder</key>
<integer>1</integer>
<key>Options</key>
<array>
<dict>
<key>Identifier</key>
<string>languageChoice</string>
<key>Units</key>
<dict>
<key>Objective-C</key>
<dict>
<key>Nodes</key>
<array>
<string>ViewController.h:comments</string>
<string>ViewController.h:imports:importCocoa</string>
<string>ViewController.h:interface(___FILEBASENAME___ : UIViewController)</string>
<string>ViewController.m:comments</string>
<string>ViewController.m:imports:importHeader:ViewController.h</string>
<string>ViewController.m:extension</string>
<string>ViewController.m:implementation:methods:viewDidLoad(- (void\)viewDidLoad)</string>
<string>ViewController.m:implementation:methods:viewDidLoad:super</string>
<string>ViewController.m:implementation:methods:didReceiveMemoryWarning(- (void\)didReceiveMemoryWarning)</string>
<string>ViewController.m:implementation:methods:didReceiveMemoryWarning:super</string>
</array>
</dict>
<key>Swift</key>
<dict>
<key>Nodes</key>
<array>
<string>ViewController.swift:comments</string>
<string>ViewController.swift:imports:importCocoa</string>
<string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string>
<string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string>
<string>ViewController.swift:implementation:methods:viewDidLoad:super</string>
<string>ViewController.swift:implementation:methods:didReceiveMemoryWarning(override func didReceiveMemoryWarning(\))</string>
<string>ViewController.swift:implementation:methods:didReceiveMemoryWarning:super</string>
</array>
</dict>
</dict>
</dict>
</array>
<key>Definitions</key>
<dict>
<key>AppDelegate.swift</key>
<dict>
<key>Path</key>
<string>AppDelegate.swift</string>
<key>TargetIndices</key>
<array>
<integer>0</integer>
</array>
</dict>
<key>Info.plist</key>
<dict>
<key>Path</key>
<string>Info.plist</string>
<key>TargetIndices</key>
<array>
<integer>0</integer>
</array>
</dict>
<key>ViewController.swift</key>
<dict>
<key>Path</key>
<string>ViewController.swift</string>
<key>TargetIndices</key>
<array>
<integer>0</integer>
</array>
</dict>
<key>ViewController.xib</key>
<dict>
<key>Path</key>
<string>ViewController.xib</string>
<key>TargetIndices</key>
<array>
<integer>0</integer>
</array>
</dict>
</dict>
<key>Nodes</key>
<array>
<string>AppDelegate.swift</string>
<string>Info.plist</string>
<string>ViewController.swift</string>
<string>ViewController.xib</string>
</array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
这个答案有什么问题吗?请告诉我.这将为您提供基于xib的模板,创建新的自定义祖先,并允许通过添加新的定义和节点,根据需要向模板添加任意数量的文件.