[swift-evolution] [Pitch] Nesting types without nesting in place (additional)

Adrian Zubarev adrian.zubarev at devandartist.com
Wed May 18 13:00:55 CDT 2016

May I revive this idea for a discussion. 

When I posted this first I didn’t thought about creating these nested types inside extensions.

So basically I could do this (over and over):

extension SomeClass {
   class NestedClass { … }

But we have to surround a new nested type by an extension scope which is more boilerplate to my eyes than just `class SomeClass.NestedClass` instead.

Is this worth a proposal?

Adrian Zubarev
Sent with Airmail

Am 12. Mai 2016 bei 16:04:23, Adrian Zubarev (adrian.zubarev at devandartist.com) schrieb:

As you may know we can nest types for shiny namespacing (protocol nesting might follow in Swift 3 as well).

What if we could create Types separated by a `.` character to determine that this is a nested type to stop building type pyramides, which could be/look ugly in some cases.

Imagine SomeClass and NestedClass are some huge and complex types. It might become hard to read if we had to build them in place just for good namespacing.

class SomeClass {
   class NestedClass {
      enum Error {}
   enum Error {}

Split this to something like this:

class SomeClass {}

enum SomeClass.Error {}

class SomeClass.NestedClass {
    enum Error {} // nesting is still allowed

Extensions already allow that.

extension SomeClass.NestedType {}

What do you think? Is it something for Swift 3?

Adrian Zubarev
Sent with Airmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160518/572ec90f/attachment.html>

More information about the swift-evolution mailing list