I first read about this idea of namespacing using enums
in the article Easy Namespacing in Swift by @khanlou.
For example, for my library Zhi,
I have a file which only has these 2 lines to create a "namespace":
public enum Zhi {
}
Then in other files, I can do this to add to the namespace:
public extension Zhi {
class StyleParser {
//...
}
}
As mentioned in the article, a major limitation is it doesn't work for protocols. So this doesn't work:
public extension Zhi {
protocol P {}
}
But otherwise, using enum
s as a namespace is a great way to organize your code.
Your feedback is valuable: Do you want more nuggets like this? Yes or No
.
.