Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct TextFormatting: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
- struct StringInterpolation: StringInterpolationProtocol {
- var output: Text = Text(verbatim: "")
- init(literalCapacity: Int, interpolationCount: Int) {
- // TODO
- }
- mutating func appendLiteral(_ literal: String) {
- output = output + Text(literal)
- }
- // append bold text
- mutating func appendInterpolation(bold: String) {
- output = output + Text(bold).bold()
- }
- }
- var text: Text
- init(stringLiteral value: String) {
- text = Text(verbatim: value)
- }
- init(stringInterpolation: StringInterpolation) {
- text = stringInterpolation.output
- }
- }
- extension Text {
- init(_ html: TextFormatting) {
- self = html.text
- }
- }
- let boldly = "boldly"
- struct ContentView : View {
- var body: some View {
- List(0 ..< 5) { item in
- Text("To \(bold: boldly) go")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement