Is there better way to create a `AttributedString` for a let property?

struct AttributedStringMarkdownList: View {
    let s: AttributedString = {
        do {
            return try AttributedString(
                markdown: """
                    - Lorem ipsum dolor sit amet.
                    - Ut dolores quaerat non nesciunt nobis ut ullam galisum ea dolorum sint sit repudiandae placeat ut ipsa quia.
                    - At internos voluptatibus ea repellat assumenda et fuga dicta ea voluptatum repellendus aut libero reiciendis.
                    """
            )
        } catch {
            fatalError()
        }
    }()

    var body: some View {
        Text(s)
    }
}

(BTW, markdown list doesn't seem to work, maybe it's not implemented?)

Any reason you can't simply do let s = try! AttributedString(markdown: "...") if you are just going to fatalError?

3 Likes

No reason. Just didn't think of it.

Thanks!

1 Like