Hi all,
In Swift, I often see static helper functions grouped in an enum without any cases, like this:
enum StringUtils {
static func camelCaseToSnakeCase(_ input: String) -> String {
// implementation
}
}
Since this enum has no cases, it cannot be instantiated – which is exactly the point.
It’s meant to group related functionality without any stored state, and without the need for instantiation.
This pattern avoids writing a struct with a private init() and makes the intent clearer:
"This is just a static utility, not an object."
You’ll often see this used for things like:
AnalyticsEvents.track(_:)
My question:
Is this use of a case-less enum considered good practice in Swift when building static-only helpers?
Or is there a better alternative for expressing intent and preventing instantiation?
I’d appreciate any insight – especially if there’s official guidance or references from the Swift core team.
Thanks!
Topic:
Programming Languages
SubTopic:
Swift