Created
July 18, 2017 09:43
-
-
Save dudarenko-io/9db60c1dd1f9241f4bdcf82f922d0794 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 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