Created
June 15, 2019 12:01
-
-
Save mortenbekditlevsen/1b8a14224defbaba6b7d9cca572e8910 to your computer and use it in GitHub Desktop.
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
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") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment