Last active
June 19, 2021 17:30
-
-
Save froggomad/867fbbf7d59c8886cf4f9ddd9aebcbb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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