Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add String extensions (init and stringValue) to Swift enums #87

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

mrousavy
Copy link
Owner

Before:

public typealias Powertrain = margelo.nitro.image.Powertrain

After:

public typealias Powertrain = margelo.nitro.image.Powertrain

public extension Powertrain {
  init?(fromString string: String) {
    switch string {
      case "electric":
        self = .electric
      case "gas":
        self = .gas
      case "hybrid":
        self = .hybrid
      default:
        return nil
    }
  }

  var stringValue: String {
    switch self {
      case .electric:
        return "electric"
      case .gas:
        return "gas"
      case .hybrid:
        return "hybrid"
    }
  }
}

Resolves #85

@mrousavy mrousavy merged commit dc861b0 into main Aug 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS string enums -> Swift string enums
1 participant