Last active
December 23, 2020 14:21
-
-
Save atierian/422757e1926500bbd5b9b9cfb873f5e0 to your computer and use it in GitHub Desktop.
Strike through String while maintaining String type
This file contains 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
//Doesn't work with all characters - use cautiously. NSAttributedString is preferred. | |
extension String { | |
var strikeThrough: String { | |
guard let strikeThrough = "\u{0336}".unicodeScalars.first else { | |
return "" | |
} | |
return self.map { char -> String in | |
var c = UnicodeScalarView(char.unicodeScalars) | |
c.append(strikeThrough) | |
return String(c) | |
}.joined() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment