Mac*_*jda 9 xcode templates swift xcode9-beta xcode9
下载Xcode 9 beta后,我发现文件模板系统发生了变化.
例如,我有一个创建2个文件的简单模板(它可能根本不应该以这种方式工作).基本文件名是
___ ___ FILEBASENAME斯威夫特
和
___ ___ FILEBASENAME View.swift
它创建了TableCell.swift和TableCellView.swift,这里是代码:
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//
import Foundation
import UIKit
class ___FILEBASENAME___: UITableViewCell {
let mainView = ___FILEBASENAME___View()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupCell()
contentView.addSubview(mainView)
mainView.setupView()
}
fileprivate func setupCell() {
backgroundColor = UIColor.clear
selectionStyle = .none
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Run Code Online (Sandbox Code Playgroud)
并查看文件:
//
// ___FILENAME___
// ___PROJECTNAME___
//
// Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//
import Foundation
import UIKit
import SnapKit
fileprivate struct Constants {
}
class ___FILEBASENAME___View: UIView {
func setupView() {
setupSelf()
}
fileprivate func setupSelf() {
snp.makeConstraints { (make) in
make.leading.trailing.top.bottom.equalTo(0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
要创建这个文件,我只是从中挑选模板
新文件......
菜单,为ex添加名称.TableCell并点击进入.现在,当我这样做时,我的输出看起来像这样:
import Foundation
import UIKit
class TableCell: UITableViewCell {
let mainView = TableCellView()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupCell()
contentView.addSubview(mainView)
mainView.setupView()
}
fileprivate func setupCell() {
backgroundColor = UIColor.clear
selectionStyle = .none
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Run Code Online (Sandbox Code Playgroud)
和
import Foundation
import UIKit
import SnapKit
fileprivate struct Constants {
}
class NewCellView: UIView {
func setupView() {
setupSelf()
}
fileprivate func setupSelf() {
snp.makeConstraints { (make) in
make.leading.trailing.top.bottom.equalTo(0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是,在Xcode 9中他们改变了模板中的东西(在游乐场中有模板的东西,新手如何在游乐场中使用模板?).
回到问题,现在从模板创建文件后,TableCell.swift看起来一样,但由于这种变化,TableCellView.swift变得疯狂.
___FILEBASENAME___View
变得新鲜
___FILEBASENAME___
所以现在当我创建TableCellView时,它看起来像这样:
import Foundation
import UIKit
import SnapKit
fileprivate struct Constants {
}
class TableCellViewView: UIView {
func setupView() {
setupSelf()
}
fileprivate func setupSelf() {
snp.makeConstraints { (make) in
make.leading.trailing.top.bottom.equalTo(0)
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我创建具有彼此依赖关系的多个文件时问题变得更加复杂,例如我将TableCellManager与TableCellViewControllerDelegate委托,当创建文件时,现在它看起来像这样
TableCellManagerViewControllerDelegate
而只是
TableViewControllerDelegate
如果新创建的文件是例如,则根据范围替换___FILEBASENAME___
___ ___ FILEBASENAME View.swift
使用关键字"Table"创建TableView.swift - 其中___FILEBASENAME___不是"Table"而是"TableView"
谁能告诉我是否有办法处理它?也许有一些像___KEYWORD___这样的新东西?在创建新文件时,我想在旧版本的Xcode中输入一个类似___FILEBASENAME___的关键字.救命!
Ren*_*fer 10
我在github上为Xcode 9,Beta 4提供了一个可行的解决方案.请查看:https://github.com/reni99/Xcode-VIPER-Template
我从这里得到了解决方案:https://github.com/infinum/iOS-VIPER-Xcode-Templates/tree/master/VIPER%20Templates/Module.xctemplate/UIViewController
你要找的是这个变量:___ VARIABLE_moduleName___
确保根据您的需要调整TemplateInfo.plist.
希望这可以帮助 :)
干杯