PascalCaseKit

1.0.1

Convert enum rawValues to Pascal Case
bbauman1/PascalCaseKit

What's New

First production ready release

2022-07-29T01:52:50Z

PascalCaseKit

Languages my twitter

Converts Swift enum rawValues to Pascal Case.

Why

In Swift we commonly have an enum representing something that is defined in Pascal Case, such as Color and Image assets. To do this we have to manually override the compiler's synthesized RawValue, because it outputs in Camel Case, which is a bummer.

Example

enum Colors: String {
    case neonGreen = "NeonGreen"
}
👎

With PascalCaseKit, the RawValue is automatically converted to PascalCase.

enum Colors: String, PascalCaseRepresentable {
    case neonGreen
}

Colors.neonGreen.rawValue // NeonGreen
👍

Design Decisions

The conversion to Pascal Case should be completely transparent to the consumer. The desired String must be accessed through rawValue and not a new variable.

Limitations

Due to the core design decision above, an enum case cannot choose to override the rawValue like you normally can. Any overrides are ignored.

enum Colors: String, PascalCaseRepresentable {
    case neonGreen = "blue"
}

Colors.neonGreen.rawValue // NeonGreen
🤷

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 21:28:24 GMT-0900 (Hawaii-Aleutian Daylight Time)