[swift-evolution] Concatenating classes

Joe Groff jgroff at apple.com
Fri Mar 31 11:58:55 CDT 2017


> On Mar 31, 2017, at 9:43 AM, Lee M via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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.

Could you be more specific about what the problem is you're having? Sounds like a bug.

-Joe

> 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() { }
> }
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list