Skip to content

Instantly share code, notes, and snippets.

@atierian
Last active December 23, 2020 14:21
Show Gist options
  • Save atierian/422757e1926500bbd5b9b9cfb873f5e0 to your computer and use it in GitHub Desktop.
Save atierian/422757e1926500bbd5b9b9cfb873f5e0 to your computer and use it in GitHub Desktop.
Strike through String while maintaining String type
//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