目录
目录README.md

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
🤷
关于
35.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号