Skip to content

Instantly share code, notes, and snippets.

@froggomad
Last active June 19, 2021 17:30
Show Gist options
  • Save froggomad/867fbbf7d59c8886cf4f9ddd9aebcbb6 to your computer and use it in GitHub Desktop.
Save froggomad/867fbbf7d59c8886cf4f9ddd9aebcbb6 to your computer and use it in GitHub Desktop.
enum Fruit: String {
case apple
case orange
case dragonFruit
var description: String {
var name: String = ""
for char in String(describing: rawValue) {
let strChar = String(char)
if strChar != strChar.uppercased() {
name.append(strChar)
} else {
// add a space when we come to the camel-cased character
name.append(" \(strChar)")
}
}
return name.capitalized
}
var viewModel: ProduceViewModel {
ProduceViewModel(description: description)
}
}
enum Vegetable: String {
case broccoli
case carrot
case sweetPeas
var description: String {
var name: String = ""
for char in String(describing: rawValue) {
let strChar = String(char)
if strChar != strChar.uppercased() {
name.append(strChar)
} else {
// add a space when we come to the camel-cased character
name.append(" \(strChar)")
}
}
return name.capitalized
}
var viewModel: ProduceViewModel {
ProduceViewModel(description: description)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment