我一直在使用Generamba(https://github.com/rambler-digital-solutions/Generamba)为iOS下的VIPER架构下的每个模块创建模板文件。
它节省了大量时间,但仍然需要通过终端命令来运行Generamba并创建文件。有没有人知道如何将这些模板直接嵌入到XCode 8中?
由于
答案 0 :(得分:5)
您可以使用templates inside Xcode生成VIPER课程。看一下这个repository,它已经为你实现了基本的VIPER文件。
希望它有所帮助。
答案 1 :(得分:3)
我不熟悉Generamba
,但要使Xcode
能够识别您的模板:
将您的Template.swift
文件放在名为MyTemplate.xctemplate
的文件夹中
通过向Templateinfo.plist
添加MyTemplate.xctemplate
告诉Xcode一些有关您模板的详细信息(请参阅下面的示例)。
将MyTemplate.xctemplate
复制到~/Library/Developer/Xcode/Templates/File\ Templates/Custom
。
完成此操作后,模板会显示在Xcode
new File
模板选择菜单的底部。
示例:
您可以使用被Xcode
替换的环境变量占位符。
这是一个名为Worker.swift
的简单示例模板:
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright (c) ___YEAR___ ___ORGANIZATIONNAME___. All rights reserved.
//
// This file was generated. DO NOT MODIFY !
//
import Foundation
class ___FILEBASENAMEASIDENTIFIER___Worker {
//implementation goes here
}
其示例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>DefaultCompletionName</key>
<string>MyWorker</string>
<key>Description</key>
<string>This generates a new worker.</string>
<key>Kind</key>
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
<key>Options</key>
<array>
<dict>
<key>Default</key>
<string>___VARIABLE_sceneName:identifier___Worker</string>
<key>Description</key>
<string>The worker name</string>
<key>Identifier</key>
<string>workerName</string>
<key>Name</key>
<string>Worker Name:</string>
<key>Required</key>
<true/>
<key>Type</key>
<string>static</string>
</dict>
</array>
<key>Platforms</key>
<array>
<string>com.apple.platform.iphoneos</string>
</array>
<key>SortOrder</key>
<string>4</string>
<key>Summary</key>
<string>Summery</string>
</dict>
您还可以在MyTemplate.xctemplate
目录中放置多个文件,以使Xcode一次创建多个文件。对于VIPER
模板,您可以让Xcode一次创建一个完整的VIPER
场景。
你可以找到工作示例加上makefile
in this "Clean Swift" template repo(Clean Swift是Swift的另一种清洁架构方法)。
答案 2 :(得分:0)
看看ViperC它同时支持 Objective-C 和 Swift 。您还可以为您创建的模块创建测试类。测试类使用Quick
和Expecta
使用 Objective-C ,使用Quick
和Nimble
获取 Swift 。