Skip to content

Instantly share code, notes, and snippets.

@dudarenko-io
Created July 18, 2017 09:43
Show Gist options
  • Save dudarenko-io/9db60c1dd1f9241f4bdcf82f922d0794 to your computer and use it in GitHub Desktop.
Save dudarenko-io/9db60c1dd1f9241f4bdcf82f922d0794 to your computer and use it in GitHub Desktop.
enum Style {
case normal
case uppercased
}
extension Style {
func applyLetterCaseToText(_ text: String) -> String {
switch self {
case .normal:
return text
case .uppercased:
return text.uppercased()
}
}
}
let text = "Lorem ipsum"
let style = Style.uppercased
let styledText = style.applyLetterCaseToText(text)
extension String {
func applyingLetterCase(_ style: Style) -> String {
return style.applyLetterCaseToText(self)
}
}
let anotherStyledText = text.applyingLetterCase(.uppercased)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment