有没有办法制作生成View-Controller对的Xcode模板?

时间:2017-06-17 10:08:48

标签: swift xcode

我在创建UIViewController / UIView对时经常使用此模式。如果我可以在Xcode中定义一个模板,那么我可以点击New File - > [模板]并生成MyViewController.swiftMyView.swift,如下例所示。

MyViewController.swift

class MyViewController: UIViewController {

    override func loadView() {
        self.view = MyView()
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
}

extension MyViewController : MyViewDelegate
{
    // Provide data, pop off a navigation stack, etc
}

MyView.swift

protocol MyViewDelegate : class {
}

class MyView: UIView
{
    weak var delegate : MyViewDelegate?

    // MARK: - Initialization

    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setup()
    }

    func setup()
    {
        // Configure views

        // Assemble

    }
}

0 个答案:

没有答案