Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct TextFormatting: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
  4. struct StringInterpolation: StringInterpolationProtocol {
  5. var output: Text = Text(verbatim: "")
  6.  
  7. init(literalCapacity: Int, interpolationCount: Int) {
  8. // TODO
  9. }
  10.  
  11. mutating func appendLiteral(_ literal: String) {
  12. output = output + Text(literal)
  13. }
  14.  
  15. // append bold text
  16. mutating func appendInterpolation(bold: String) {
  17. output = output + Text(bold).bold()
  18. }
  19. }
  20.  
  21. var text: Text
  22.  
  23. init(stringLiteral value: String) {
  24. text = Text(verbatim: value)
  25. }
  26.  
  27. init(stringInterpolation: StringInterpolation) {
  28. text = stringInterpolation.output
  29. }
  30. }
  31.  
  32. extension Text {
  33. init(_ html: TextFormatting) {
  34. self = html.text
  35. }
  36. }
  37.  
  38. let boldly = "boldly"
  39.  
  40. struct ContentView : View {
  41. var body: some View {
  42. List(0 ..< 5) { item in
  43. Text("To \(bold: boldly) go")
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement