Last active
June 19, 2021 17:28
-
-
Save froggomad/09e70274772629810dfc2b7ca0b99b45 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 | |
} | |
} | |
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment