【发布时间】:2017-12-02 17:47:56
【问题描述】:
下载 Xcode 9 beta 后,我注意到文件模板系统发生了变化。
例如,我有一个创建 2 个文件的简单模板(它可能根本不应该这样工作)。基本文件名是
___FILEBASENAME___.swift
和
___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")
}
}
并查看文件:
//
// ___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)
}
}
}
为了创建这个文件,我只是从
中挑选模板新文件...
菜单,为 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")
}
}
和
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)
}
}
}
现在的问题是,在 Xcode 9 中,他们更改了模板中的内容(在 Playground 中使用模板,新手如何在 Playground 中使用模板?)。
回到问题,现在从模板创建文件后,TableCell.swift 看起来和以前一样,但是 TableCellView.swift 由于这个变化而变得疯狂。
___FILEBASENAME___查看
成为新的
___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)
}
}
}
现在,当我创建多个相互依赖的文件时,问题变得更加复杂,例如我有 TableCellManager 委托给 TableCellViewControllerDelegate,现在创建文件时看起来像这样
TableCellManagerViewControllerDelegate
而只是
TableViewControllerDelegate
___FILEBASENAME___ 根据范围被替换,例如,如果新创建的文件是
___FILEBASENAME___View.swift
使用关键字“Table”创建 TableView.swift - 其中 ___FILEBASENAME___ 不是“Table”而是“TableView”
谁能告诉我是否有办法处理它? 也许有一些新的东西,比如 ___KEYWORD___? 在创建新文件时,我想输入一个在旧版本 Xcode 中可以像 ___FILEBASENAME___ 一样工作的关键字。帮助!
【问题讨论】:
标签: swift xcode templates xcode9-beta xcode9