after downloading Xcode 9 beta, I noticed a change in the file template system.
For example, I had a simple template that created 2 files (this probably should not work at all). Base File Names
___ ___ FILEBASENAME. Coming soon
and
___ ___ FILEBASENAME View.swift
and it is created by TableCell.swift and TableCellView.swift, here are the codes:
// // ___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") } }
And file view:
// // ___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) } } }
To create these files, I simply selected a template from
New files ...
add a name for ex. TableCell and press enter. Now, when I do this, my output is as follows:
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") } }
and
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) } } }
Now the problem is that in Xcode 9 they changed the elements in the templates (something with templates on the playgrounds, how would a beginner use templates on the playgrounds anyway?).
Back to the problem, now after creating the files from the template, TableCell.swift looks the same, but TableCellView.swift goes away due to this change.
___ ___ FILEBASENAME View
becomes new
___ FILEBASENAME ___
so now when i create a TableCellView it looks like this:
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) } } }
Now the problem gets more complicated when I create several files with dependencies from each other, for example, I have a TableCellManager with a delegate in TableCellViewControllerDelegate, when creating files now it looks like
TableCellManagerViewControllerDelegate
instead, just
TableViewControllerDelegate
___ FILEBASENAME___ is replaced depending on the scope, if, for example, a new file is created
___ ___ FILEBASENAME View.swift
using the keyword "Table", creates TableView.swift - in which ___FILEBASENAME___ is not "Table", but "TableView"
Can someone tell me if there is a way to handle this? Perhaps there is something new, for example ___ KEYWORD ___? . When creating a new file, I want to enter a keyword that will work as ___FILEBASENAME___ in older versions of Xcode. HELP!