[swift-evolution] Concatenating classes

Lee M me at leemcdermott.co.uk
Fri Mar 31 11:43:45 CDT 2017


I’m building a fairly large app for macOS, and its not uncommon for a
view/view controller subclass to implement 10-20+ NSResponder methods. I
like to separate these methods from other logic/layout code. At the moment,
I’d break out my code into individual files like this:

TestViewController.swift
TestViewController+NSResponder.swift
TestViewController+…

class TestViewController: NSViewController {

}

extension TestViewController {

}

The problem is: when I try to introduce generics to the subclass, the
compiler complains about limitations on @objc extensions. The only
workaround is to concatenate everything into a larger file, which I’d
rather not do. Would it be possible to introduce a simple way to have the
compiler concatenate declarations for us? Probably creates more problems
that it solves, but worth mentioning. E.g:

class TestViewController: NSViewController {
    func foo() { }
}

class TestViewController (continued) {
    func bar() { }
}

Concatenates into:

class TestViewController: NSViewController {
    func foo() { }
    func bar() { }
}

Alternate syntax:

continued class TestViewController {
    func bar() { }
}

Slightly more exotic:

TestViewController.Type += class {
    func bar() { }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170331/77db1219/attachment.html>


More information about the swift-evolution mailing list