[swift-evolution] [Pitch] Custom Namespaces

Niels Andriesse andriesseniels at gmail.com
Wed Mar 30 00:52:35 CDT 2016

At the moment, it's not possible to define custom namespaces. They can be
emulated using static members on an enum:

enum Foo {
  static var bar: Bar
  static func baz() { }

This is not ideal, because:

   - The case shown above is semantically speaking obviously not an enum and
   shouldn't be presented as such.
   - The members are required to be static unnecessarily.
   - Not all top-level declarations can be nested like this (e.g.
   - If we allow namespaces to be reused in different files within the same
   module, this could potentially be used as a custom scope for access control
   (e.g. using the proposed private(...) syntax, so in this case

Are there any plans to allow custom namespaces (for example as shown below)?

namespace Foo {
  var bar: Bar
  func baz() { }

Alternatively, a similar situation could be achieved by introducing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160330/89d7e9b0/attachment.html>

More information about the swift-evolution mailing list