Clicky

iOS Dev Nugget 272 Namespacing using Enums

.

Need to run a code review on your codebase? Hire me

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 enums 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

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues